home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / MONITOR / ANSI137.ARJ / ANSI.ASM next >
Assembly Source File  |  1991-04-23  |  107KB  |  1,967 lines

  1. ;------------------------------------------------------------------------;
  2. ;  ANSI.COM - Replacement for the ANSI.SYS console device driver.        ;
  3. ;  Unlike ANSI.SYS which must be installed at boot time, ANSI.COM        ;
  4. ;  can be installed and uninstalled at anytime.  Enhancements include    ;
  5. ;  a fast screen write and variable sized keyboard reassignment buffer.  ;
  6. ;                                                                        ;
  7. ;  Update 3/2/89 - Fix for DOS function 0Bh, Check Standard Input Status ;
  8. ;                      and STDIN in ANSI_INT_21 handler.                 ;
  9. ;                  Leading zero inserted for Device Status Report for    ;
  10. ;                      single digit cursor positions.                    ;
  11. ;                  INFORMATION typo 40 for 40H.                          ;
  12. ;                  WRITE_FAST modified to handle CR and LF instead of    ;
  13. ;                      WRITE_CHAR.                                       ;
  14. ;  Update 3/7/89 - Fix for CLS in graphics mode.          Version 1.2    ;
  15. ;                                                                        ;
  16. ;  Update 8/8/89 - STI added to INT 21 and 29 handler.    Version 1.3    ;
  17. ;:                                                                       ;
  18. ;: Update 01/01/90 - [KON | KOFF] and [PON | POFF] added  Version 1.31   ;
  19. ;:                   (all changes marked with ;: - Gary Meeker)          ;
  20. ;| Update 03/23/90 - /Q option added for no output when exectued  1.32   ;
  21. ;|                   (all changes marked with ;| - Gary Meeker)          ;
  22. ;; Update 05/16/90 - removed Syntax from output unless needed     1.33   ;
  23. ;;                   added /T test for load.                             ;
  24. ;;                   (all changes marked with ;; - Gary Meeker)          ;
  25. ;. Update 10/28/90 - Added /P nn top of screen protection mode    1.34   ;
  26. ;.                   (all changes marked with ;. - Gary Meeker)          ;
  27. ;@ Update 12/01/90 - Added PCBoard @X## color code support        1.35   ;
  28. ;@                   also added @Variable@ Support                       ;
  29. ;@                   added /S to load stats data from file               ;
  30. ;@                   (all changes marked with ;@ - Gary Meeker)          ;
  31. ;&                                                                       ;
  32. ;& Update 12/12/90 - My mistake, I didn't realize @X00 saved      1.36   ;
  33. ;&                   the color and @XFF restored it. Works now.          ;
  34. ;&                   Also made prompts return to start of line           ;
  35. ;&                   when cleared (like PCBoard does) & QON              ;
  36. ;&                   now changes @MORE@ & @PAUSE@ into @WAIT@            ;
  37. ;&                   (all changes marked with ;& - Gary Meeker)          ;
  38. ;$ Update  4/22/91 - Change set cursor routine. If new position   1.37   ;
  39. ;$                   is off the screen use the last row or column.       ;
  40. ;$                   Added switch to not include PCB code.               ;
  41. ;$                   Corrected syntax display.                           ;
  42. ;$                   Modified CLS to honor protected (/P) lines.         ;
  43. ;$                   Modified /T to returned status switches.            ;
  44. ;$                   Modified /P to accept * to mean current row-1.      ;
  45. ;$                   (all changes marked with ;$ - Wayne Mingee)         ;
  46. ;                                                                        ;
  47. ;  PC Magazine - Michael J. Mefford                                      ;
  48. ;------------------------------------------------------------------------;
  49.  
  50. PCB            equ     0                     ;$ 1 = if PCB code wanted
  51.  
  52. _TEXT          SEGMENT PUBLIC 'CODE'
  53.                ASSUME  CS:_TEXT,DS:_TEXT,ES:_TEXT,SS:_TEXT
  54.                ORG     100H
  55. START:         JMP     INITIALIZE
  56.  
  57. ;                 DATA AREA
  58. SIGNATURE      DB      CR,SPACE,SPACE,SPACE,CR,LF
  59. COPYRIGHT      DB      "ANSI 1.3g (C) 1988 Ziff Communications Co.",CR,LF    ;.
  60. PROGRAMMER     DB      "PC Magazine ",BOX," Michael J. Mefford",CR,LF,LF,"$"
  61.                DB      CTRL_Z
  62.  
  63. CR             EQU     13
  64. LF             EQU     10
  65. CTRL_Z         EQU     26
  66. SPACE          EQU     32
  67. BOX            EQU     254
  68. ESC_CHAR       EQU     27
  69. SINGLE_QUOTE   EQU     39
  70. DOUBLE_QUOTE   EQU     34
  71. BELL           EQU     7
  72. BS             EQU     8
  73. TAB            EQU     9
  74.  
  75. OFF            EQU     1
  76. ON             EQU     2
  77. SLOW           EQU     4
  78. FAST           EQU     8
  79. KOFF           EQU     16                         ;:
  80. KON            EQU     32                         ;:
  81. POFF           EQU     64                         ;:
  82. PON            EQU     128                        ;:
  83. STATUS_MASK    EQU     1111110000000001B          ;: Set Mask and Bit
  84.  
  85. ANSI_STATE     DW      ESC_STATE
  86. STATUS         DB      ON OR FAST OR KON OR PON           ;:
  87. PARAMETERS     DB      "OFF",0,"ON",0,0,"SLOWFASTKOFFKON",0,"POFFPON",0 ;:
  88. LAST_PARAMETER EQU     $ - PARAMETERS
  89.  
  90. OLD_INT_29     DW      ?,?
  91. OLD_INT_16     DW      ?,?
  92. OLD_INT_21     DW      ?,?
  93. if PCB                                            ;$
  94. OLD_INT_08     DW      ?,?              ;@ Save Timer Interupt
  95. endif                                             ;$
  96. ATTRIBUTE      DB      7
  97. if PCB                                            ;$
  98. SAVE_ATTRIBUTE DB      ?                ;& For saving attribute
  99. endif                                             ;$
  100. SAVE_POSITION  DW      0
  101. LINE_WRAP      DB      ON
  102. QUOTE_TYPE     DB      ?
  103. ESC_COUNT      DW      0
  104. NUMBER_COUNT   DW      0
  105.  
  106. COMMAND_TABLE  LABEL   BYTE
  107. DB   "H", "A", "B", "C", "D", "f", "n", "s", "u", "K", "m", "h", "l", "p", "J"
  108. COMMAND_LENGTH EQU     $ - COMMAND_TABLE
  109.  
  110. DW   CURS_POSITION, CURSOR_UP,     CURSOR_DOWN, CURS_FORWARD, CURS_BACKWARD
  111. DW   HORZ_VERT_POS, DEVICE_STATUS, SAVE_CURSOR, RESTORE_CURS, ERASE_IN_LINE
  112. DW   SGR,           SET_MODE,      RESET_MODE,  REASSIGNMENT, CLS
  113. COMMAND_END    EQU     $ - 2
  114.  
  115. ATTRIBUTE_TABLE        LABEL    BYTE
  116. DB   00,01,04,05,07,08,30,31,32,33,34,35,36,37,40,41,42,43,44,45,46,47
  117. ATTRIBUTE_LENGTH       EQU      $ - ATTRIBUTE_TABLE
  118.  
  119. ;Format: AND mask,OR mask
  120. DB      000H,07H, 0FFH,08H, 0F8H,01H, 0FFH,80H, 0F8H,70H, 088H,00H
  121. DB      0F8H,00H, 0F8H,04H, 0F8H,02H, 0F8H,06H, 0F8H,01H, 0F8H,05H
  122. DB      0F8H,03H, 0F8H,07H, 08FH,00H, 08FH,40H, 08FH,20H, 08FH,60H
  123. DB      08FH,10H, 08FH,50H, 08FH,30H, 08FH,70H
  124. ATTRIBUTE_END          EQU      $ - 2
  125.  
  126. if PCB                                            ;$
  127. AT_VARIABLE_TABLE      LABEL BYTE                                          ;@
  128. DB   '@CLS@CLREOL@AUTOMORE@POFF@PON@QOFF@QON@BEEP@MORE@PAUSE@WAIT@HANGUP@' ;@
  129. DB   'OPTEXT@FIRSTU@FIRST@USER@CITY@HOMEPHONE@DATAPHONE@PROLTR@PRODESC@'   ;@
  130. DB   'EXPDATE@LASTDATEON@LASTTIMEON@INCONF@CONFNAME@BOARDNAME@'            ;@
  131. DB   'LASTCALLERNODE@LASTCALLERSYSTEM@EVENT@SYSOPIN@SYSOPOUT@BPS@NODE@'    ;@
  132. DB   'SYSDATE@SYSTIME@FILERATIO@BYTERATIO@'                                ;@
  133. DB   'SECURITY@NUMCALLS@NUMTIMESON@TIMELEFT@TIMELIMIT@TIMEUSED@TOTALTIME@' ;@
  134. DB   'BYTESLEFT@BYTELIMIT@DLFILES@UPFILES@KBLEFT@KBLIMIT@CONFNUM@'         ;@
  135. DB   'CURMSGNUM@HIGHMSGNUM@LOWMSGNUM@MSGREAD@MSGLEFT@NUMBLT@NUMDIR@'       ;@
  136. DB   'DAYBYTES@MINLEFT@DLBYTES@UPBYTES@EXPDAYS@'                           ;@
  137.  
  138. LAST_VARIABLE          EQU     $ - 1                                       ;@
  139.  
  140. JUMP_TABLE             LABEL WORD                                          ;@
  141. DW      CLS, ERASE_IN_LINE, AUTOMORE, AUTOOFF, AUTOOFF, QOFF, QON        ;&;@
  142. DW      BEEP, MORE, PAUSE, WAIT1, SKIP_IT                                  ;@
  143.  
  144. SUB_TABLE              LABEL BYTE                                          ;@
  145. DB      8,15,15,25,24,13,13,1,47                                           ;@
  146. DB      8,8,5,33,13,63                                                     ;@
  147. DB      52,52,5,5,5,5,2                                                    ;@
  148. DB      0,0,4,4                                                            ;@
  149. DB      2,4,2,2,2,2,2                                                      ;@
  150. DB      4,4,2,2,4,4,2                                                      ;@
  151. DB      4,4,4,4,4,2,2                                                      ;@
  152. DB      4,2,4,4,2                                                          ;@
  153.  
  154. SUB_LIST               LABEL BYTE                      ;@
  155. DB     '!OPTEXT!'                                      ;@ OPTTEXT
  156. DB     'GARY',0,0,0,0,0,0,0,0,0,0,0                    ;@ FirstU
  157. DB     'Gary',0,0,0,0,0,0,0,0,0,0,0                    ;@ First
  158. DB     'GARY MEEKER',0,0,0,0,0,0,0,0,0,0,0,0,0,0       ;@ User
  159. DB     'LAWRENCEVILLE, GA',0,0,0,0,0,0,0               ;@ City
  160. DB     '404 995-2699',0                                ;@ HomePhone
  161. DB     '404 962-1788',0                                ;@ DataPhone
  162. DB     'Z'                                             ;@ Proltr
  163. DB     'Zmodem       (Batch U/L and D/L)', 15 DUP (0)  ;@ ProDesc
  164. DB     '01-01-91'                                      ;@ ExpDate
  165. DB     '12-01-90'                                      ;@ LastDateOn
  166. DB     '08:00'                                         ;@ LastTimeOn
  167. DB     'Magazine (1) Conference ',0,0,0,0,0,0,0,0,0    ;@ InConf
  168. DB     'Magazine',0,0,0,0,0                            ;@ ConfName
  169. DB     'SHARP Technical Support Line BBS', 31 DUP (0)  ;@ BoardName
  170. DB     'MIKE BATE (RIVERDALE, GA)', 27 DUP (0)         ;@ LastCallerNode
  171. DB     'GARY MEEKER (LAWRENCEVILLE, GA)', 21 DUP (0)   ;@ LastCallerSystem
  172. DB     '04:30'                                         ;@ Event
  173. DB     '08:30'                                         ;@ SysopIn
  174. DB     '17:00'                                         ;@ SysopOut
  175. DB     '2400',0                                        ;@ bps
  176. DB     '1',0                                           ;@ Node
  177.  
  178. DD     48                                              ;@ FileRatio
  179. DD     128                                             ;@ ByteRatio
  180.  
  181. DW         120                                         ;@ Security
  182. DD       23946                                         ;@ numcalls
  183. DW        2107                                         ;@ numtimeson
  184. DW          61                                         ;@ timeleft
  185. DW         121                                         ;@ timelimit
  186. DW          59                                         ;@ timeused
  187. DW          59                                         ;@ totaltime
  188. DD     9508313                                         ;@ bytesleft
  189. DD    10238976                                         ;@ bytelimit
  190. DW          44                                         ;@ dlfiles
  191. DW        1234                                         ;@ upfiles
  192. DD        9285                                         ;@ KBLeft
  193. DD        9999                                         ;@ KBLimit
  194. DW           1                                         ;@ ConfNum
  195. DD        4734                                         ;@ CurMsgNum
  196. DD        4745                                         ;@ HighMsgNum
  197. DD           2                                         ;@ LowMsgNum
  198. DD        3456                                         ;@ MsgRead
  199. DD         987                                         ;@ MsgLeft
  200. DW          20                                         ;@ NumBlt
  201. DW          31                                         ;@ NumDir
  202. DD       30663                                         ;@ DayBytes
  203. DW          61                                         ;@ MinLeft
  204. DD      730663                                         ;@ DLBytes
  205. DD    12345678                                         ;@ UpBytes
  206. DW           0                                         ;@ ExpDays
  207. SUB_LENGTH     EQU      $ - SUB_LIST
  208.  
  209. PAUSE_TIMER    DW      182                             ;@
  210. PAUSE_DELAY    DW      182                             ;@ 10 Seconds
  211. MORE_DELAY     DW      182 * 12                        ;@ 2 Minute
  212. WAIT_DELAY     DW      182 * 12                        ;@ 2 Minute
  213.  
  214. WAIT_PROMPT    DB      'press enter to continue'       ;@
  215. WAIT_LENGTH    DW      $ - WAIT_PROMPT                 ;@
  216. MORE_PROMPT    DB      '(61 min left), (H)elp, More?'  ;@
  217. MORE_LENGTH    DW      $ - MORE_PROMPT                 ;@
  218. COMMA          DB      0                               ;@
  219. Q_STATE        DB      0                               ;&
  220. endif                                             ;$
  221.  
  222. BIOS_ACTIVE_PAGE       EQU     62H
  223. ACTIVE_PAGE    DB      ?
  224. ADDR_6845      DW      ?
  225. BIOS_CRT_MODE          EQU     49H
  226. CRT_MODE       DB      ?
  227. CRT_COLS       DW      ?
  228. CRT_LEN        DW      ?
  229. CRT_START      DW      ?
  230. CRT_DATA_LENGTH        EQU     $ - CRT_MODE
  231. CURSOR_POSN    LABEL   WORD
  232. CURSOR_COL     DB      ?
  233. CURSOR_ROW     DB      ?
  234. CRT_ROWS       DB      ?
  235.  
  236. START_SCROLL   DB      0       ;. Number of rows to protect from scrolling up
  237.  
  238. DOS_INPUT      DB      OFF
  239. BUSY_FLAG      DB      OFF
  240. REASSIGN_FLAG  DB      OFF
  241. REMOVE_FLAG    DB      ON
  242. REASSIGN_COUNT DW      0
  243. REASSIGN_POS   DW      ?
  244. FUNCTION_16    DB      ?
  245. ZR             EQU     1000000B
  246.  
  247. ESC_BUFFER_SIZE      EQU     126
  248. REASSIGNMENT_DEFAULT EQU     200
  249. REASSIGNMENT_SIZE    DW      REASSIGNMENT_DEFAULT
  250. REASSIGNMENT_MAX     EQU     60 * 1024
  251. REASSIGN_END         DW      REASSIGNMENT_BUFFER
  252. BUFFER_END           DW      REASSIGNMENT_BUFFER + REASSIGNMENT_DEFAULT
  253.  
  254. ;                   CODE AREA
  255. ;************* INTERRUPT HANDLERS *************;
  256. ;------------------------------------------------------------------------------;
  257. ; INT 29 is an undocumented interrupt called by DOS for output to the console. ;
  258. ;------------------------------------------------------------------------------;
  259.  
  260. ANSI_INT_29    PROC    FAR
  261.                STI
  262.                PUSH    AX                      ;Save all registers.
  263.                PUSH    BX
  264.                PUSH    CX
  265.                PUSH    DX
  266.                PUSH    SI
  267.                PUSH    DI
  268.                PUSH    DS
  269.                PUSH    ES
  270.                PUSH    BP
  271.  
  272.                CLD                             ;All string operations forward.
  273.                MOV     BX,CS                   ;Point to our data segment.
  274.                MOV     DS,BX
  275.                MOV     ES,BX
  276.                CALL    ANSI_STATE              ;Call the current state of
  277.                                                ; the ANSI Esc sequence.
  278.                POP     BP
  279.                POP     ES
  280.                POP     DS
  281.                POP     DI
  282.                POP     SI
  283.                POP     DX
  284.                POP     CX
  285.                POP     BX
  286.                POP     AX                      ;Restore all registers and
  287.                IRET                            ; and return
  288. ANSI_INT_29    ENDP
  289.  
  290. ;------------------------------------------------;
  291.  
  292. ANSI_INT_21    PROC    FAR
  293.                PUSHF
  294.                CMP     AH,0BH                  ;If DOS function 0Bh (Check
  295.                JNZ     CK_INPUT                ; Standard Input Status)
  296.                CMP     CS:REASSIGN_FLAG,ON     ; and reassignment in progress,
  297.                JNZ     CK_INPUT                ; including a Device Status
  298.                CALL    DWORD PTR CS:OLD_INT_21 ; Request, then process call in
  299.                MOV     AL,0FFH                 ; case control break pressed;
  300.                IRET                            ; then return 0FFh for char ready
  301.  
  302. CK_INPUT:      CMP     AH,3FH                  ;Read from STDIN?
  303.                JNZ     CK_CONSOLE
  304.                OR      BX,BX
  305.                JZ      INPUT
  306.  
  307. CK_CONSOLE:    CMP     AH,0AH                  ;If DOS Int 21 functions Ah,
  308.                JZ      INPUT                   ; 7h, 1h or console input (6h)
  309.                CMP     AH,7                    ; then tell INT 16, DOS input
  310.                JZ      INPUT                   ; is active.
  311.                CMP     AH,1
  312.                JZ      INPUT
  313.                CMP     AH,8
  314.                JZ      INPUT
  315.                CMP     AH,6
  316.                JNZ     QUICK21_EXIT
  317.                CMP     DL,0FFH
  318.                JZ      INPUT
  319. QUICK21_EXIT:  POPF                              ;If not, let the original
  320.                JMP     DWORD PTR CS:OLD_INT_21   ; interrupt process the call.
  321.  
  322. INPUT:         POPF
  323.                MOV     CS:DOS_INPUT,ON           ;INT 16 handler flag.
  324.                PUSHF
  325.                CALL    DWORD PTR CS:OLD_INT_21   ;Emulate an interrupt.
  326.                MOV     CS:DOS_INPUT,OFF          ;Turn flag back off.
  327.                STI
  328.                RET     2                         ;Return with current flags.
  329. ANSI_INT_21    ENDP
  330.  
  331. ;-----------------------------------------------------------------;
  332. ; If we get here via a DOS console input call, any awaiting key   ;
  333. ; in keyboard buffer is checked to see if it is to be reassigned. :
  334. ;-----------------------------------------------------------------;
  335.  
  336. ANSI_INT_16    PROC    FAR
  337.                STI                             ;Interrupts back on.
  338.                PUSHF                           ;Preserve flags on stack.
  339.                PUSH    BP
  340.                PUSH    DS
  341.                PUSH    AX
  342.                PUSH    CS                      ;Point to our data.
  343.                POP     DS
  344.  
  345.                CMP     DOS_INPUT,OFF           ;If not called via a DOS
  346.                JZ      QUICK16_EXIT            ; console input call, exit.
  347.                CMP     BUSY_FLAG,ON            ;If already processing a call,
  348.                JZ      QUICK16_EXIT            ; exit.
  349.                CLD                             ;All string operations forward.
  350.                MOV     BP,SP                   ;Base reference to flags on stack
  351.                MOV     FUNCTION_16,AH          ;Save function request.
  352.                AND     AH,NOT 10H              ;Strip possible extended request.
  353.                JZ      GET_KEY                 ;If zero, it's wait for a key.
  354.                DEC     AH                      ;Else, decrement.  If zero it's
  355.                JZ      KEY_STATUS              ; key status, else exit.
  356.  
  357. QUICK16_EXIT:  POP     AX                      ;Restore registers and let
  358.                POP     DS                      ; original interrupt handler
  359.                POP     BP                      ; process the call.
  360.                POPF
  361.                JMP     DWORD PTR CS:OLD_INT_16
  362.  
  363. KEY_STATUS:    OR      BYTE PTR [BP+6],ZR      ;Assume none ready; ZR = 1.
  364. GET_KEY:       MOV     BUSY_FLAG,ON            ;Non-reentrant; flag busy.
  365.                POP     AX
  366.                PUSH    BX                      ;Save some more registers.
  367.                PUSH    CX
  368.                PUSH    DX
  369.                PUSH    SI
  370.                PUSH    DI
  371.                CMP     REASSIGN_FLAG,ON        ;Already in process of reassign?
  372.                JZ      CK_BUFFER               ;If yes, check kbd buffer.
  373.  
  374.                PUSHF                           ;Else, emulate an interrupt.
  375.                CALL    DWORD PTR OLD_INT_16
  376.                PUSHF                           ;Status call results in flags.
  377.                TEST    FUNCTION_16,1           ;Was it a status call?
  378.                JZ      CK_DUP                  ;If no, check key returned.
  379.                POPF                            ;Else, retrieve status results.
  380.                JZ      INT16_EXIT              ;If zero, no key waiting.
  381.                AND     BYTE PTR [BP+6],NOT ZR  ;Else, ZR = 0.
  382.                PUSHF                           ;PUSHF just to keep stack right.
  383.  
  384. CK_DUP:        POPF                            ;Fix stack.
  385.                TEST    STATUS,KOFF             ;:If KOFF then we don't do
  386.                JNZ     INT16_EXIT              ;:re-assignments
  387.                MOV     BX,AX                   ;Match procedure wants key in BX.
  388.                CALL    CK_MATCH                ;Check reassignment buffer.
  389.                JC      INT16_EXIT              ;If no match, exit.
  390.                MOV     AX,[DI]                 ;Else, retrieve string length.
  391.                SUB     AX,3                    ;Adjust for length word and match
  392.                ADD     DI,3                    ; byte; same for string pointer.
  393.                OR      BL,BL                   ;Extended key? ie. key = 0.
  394.                JNZ     STORE_COUNT             ;If no, save length and pointer.
  395.                DEC     AX                      ;Else, adjust for extended code.
  396.                INC     DI
  397. STORE_COUNT:   MOV     REASSIGN_COUNT,AX       ;Save string length.
  398.                MOV     REASSIGN_POS,DI         ;Save pointer to string.
  399.                MOV     REASSIGN_FLAG,ON        ;Flag that replacement in effect.
  400. CK_BUFFER:     TEST    FUNCTION_16,1           ;Was it a key wait function call?
  401.                JNZ     RETRIEVE                ;If no, key status; get it.
  402.                CMP     REMOVE_FLAG,OFF         ;Removed it from kbd buffer?
  403.                JZ      RETRIEVE                ;If yes, get reassignment.
  404.                MOV     AH,FUNCTION_16          ;Else, eat the replaced character
  405.                INT     16H                     ; via INT 16.
  406.                MOV     REMOVE_FLAG,OFF         ;Flag character eaten.
  407.  
  408. RETRIEVE:      MOV     DI,REASSIGN_POS         ;Retrieve pointer to string.
  409.                MOV     AX,[DI]                 ;Retrieve replacement character.
  410.                TEST    FUNCTION_16,1           ;Is it a key wait function call?
  411.                JZ      REMOVE                  ;If yes, bump pointer up one.
  412.                AND     BYTE PTR [BP+6],NOT ZR  ;If no, status call; ZR = 0
  413.                JMP     SHORT INT16_EXIT        ;All done.
  414.  
  415. REMOVE:        INC     REASSIGN_POS            ;Move pointer to next character.
  416.                DEC     REASSIGN_COUNT          ;One less character to replace.
  417.                JZ      REASSIGN_DONE           ;If end of string, reset flags.
  418.                OR      AL,AL                   ;Else, extended replacement?
  419.                JNZ     INT16_EXIT              ;If no, done here.
  420.                INC     REASSIGN_POS            ;Else adjust pointers.
  421.                DEC     REASSIGN_COUNT
  422.                JNZ     INT16_EXIT              ;End of string?
  423. REASSIGN_DONE: MOV     REASSIGN_FLAG,OFF       ;If yes, reset flags.
  424.                MOV     REMOVE_FLAG,ON
  425.  
  426. INT16_EXIT:    MOV     BUSY_FLAG,OFF           ;Reset the busy flag.
  427.                POP     DI                      ;Restore registers.
  428.                POP     SI
  429.                POP     DX
  430.                POP     CX
  431.                POP     BX
  432.                POP     DS
  433.                POP     BP
  434.                POPF                            ;Flags on stack have status
  435.                RET     2                       ; results; kill old flags.
  436. ANSI_INT_16    ENDP
  437. if PCB                                            ;$
  438. ANSI_INT_08    PROC    FAR                      ;@
  439.                CMP     CS:[PAUSE_TIMER],0       ;@
  440.                JE      SKIP_TIMER               ;@
  441.                DEC     CS:[PAUSE_TIMER]         ;@
  442. SKIP_TIMER:    JMP     DWORD PTR CS:OLD_INT_08  ;@
  443. ANSI_INT_08    ENDP                             ;@
  444. endif                                             ;$
  445. ;************* ANSI ESCAPE STATE ROUTINES ************* ;
  446.  
  447. ESC_STATE:     MOV     BX,OFFSET BRACKET_STATE ;Assume Esc character.
  448.                CMP     AL,ESC_CHAR             ;Is it Esc?  If yes, store
  449.                JZ      SHORT_JUMP              ; char. and next state.
  450. if PCB                                            ;$
  451.                CMP     DOS_INPUT,ON            ;@ Called via DOS Input?
  452.                JE      WRITE_CHAR2             ;@ Yes, Nevermind
  453.                MOV     BX,OFFSET ATX_STATE     ;@ No, Assume @ Character
  454.                CMP     AL,"@"                  ;@ Is it @? If yes, store
  455.                JZ      SHORT_JUMP              ;@ char. and next state.
  456. WRITE_CHAR2:
  457. endif                                             ;$
  458.                JMP     WRITE_CHAR              ;@ Else, normal char; write it.
  459. ;------------------------------------------------;
  460.  
  461. BRACKET_STATE: MOV     BX,OFFSET SPECIAL_STATE ;Assume left bracket.
  462.                CMP     AL,"["                  ;Is it left bracket?  If yes,
  463. SHORT_JUMP:    JZ      STORE_STATE             ;store char. and next state.
  464.                JMP     FLUSH_BUFFER            ;Else, flush Esc out of buffer.
  465.  
  466. ;---------------------------------------------------------------;
  467. ; Must process <ESC>[2J (CLS) regardless if ANSI.COM ON or OFF. ;
  468. ;---------------------------------------------------------------;
  469.  
  470. SPECIAL_STATE: MOV     BX,OFFSET CLS_STATE     ;Assume Erase in Display code.
  471.                CMP     AL,"2"                  ;Is it the "2" ?
  472.                JZ      STORE_STATE             ;If yes, progress to next state.
  473.                TEST    STATUS,OFF              ;Else, is ANSI OFF ?
  474.                JNZ     FLUSH_BUFFER            ;If yes, flush Esc, bracket.
  475.                MOV     BX,OFFSET PARAM_STATE   ;Else, check for first Set,
  476.                CMP     AL,"="                  ; Reset Mode characters of
  477.                JZ      STORE_STATE             ; "=" and "?".
  478.                CMP     AL,"?"
  479.                JZ      STORE_STATE             ;If found, store.
  480.                JMP     SHORT DO_PARAMETER      ;Else, check other codes.
  481.  
  482. ;------------------------------------------------;
  483.  
  484. CLS_STATE:     CMP     AL,"J"                  ;Is it second character of CLS?
  485.                MOV     DI,OFFSET COMMAND_END   ;If yes, execute
  486.                JZ      EXECUTE                 ; Erase in Display procedure.
  487.                TEST    STATUS,OFF              ;ANSI OFF?  If yes, flush buffer.
  488.                JNZ     FLUSH_BUFFER            ; If not fall through to process.
  489.                MOV     BYTE PTR NUMBER_BUFFER,2   ;Store the previous 2.
  490. DO_PARAMETER:  MOV     ANSI_STATE,OFFSET PARAM_STATE  ;Parameter state.
  491.  
  492. ;------------------------------------------------;
  493.  
  494. PARAM_STATE:   CALL    CK_QUOTE                ;Is it single or double quotes?
  495.                JZ      STORE_STATE             ;If yes, store string state.
  496.                CMP     AL,";"                  ;Is it semi-colon delimiter?
  497.                JNZ     CK_NUMBER               ;If no, check if number.
  498.                INC     NUMBER_COUNT            ;Else, increment number count.
  499.                JMP     SHORT BUFFER_CHAR       ;Buffer the semi-colon.
  500.  
  501. CK_NUMBER:     CMP     AL,"0"                  ;Is it below 0 ?
  502.                JB      FLUSH_BUFFER            ;If yes, illegal; flush buffer.
  503.                CMP     AL,"9"                  ;Else, is it above 9 ?
  504.                JA      DO_COMMAND              ;If yes, check for command char.
  505.                CALL    ACCUMULATE              ;Else it's a number; accumulate.
  506.                JMP     SHORT BUFFER_CHAR       ;Buffer the character.
  507.  
  508. DO_COMMAND:    MOV     DI,OFFSET COMMAND_TABLE ;Point to legal ANSI commands.
  509.                MOV     CX,COMMAND_LENGTH       ;Number of commands.
  510.                REPNZ   SCASB                   ;Check for a match.
  511.                JNZ     FLUSH_BUFFER            ;If no match, flush sequence.
  512.                INC     NUMBER_COUNT            ;Else, increment for last number.
  513.                MOV     DI,OFFSET COMMAND_END   ;Point to appropriate command
  514.                SHL     CX,1                    ; processing procedure.
  515.                SUB     DI,CX
  516. EXECUTE:       CALL    GET_BIOS_DATA           ;Get cursor position data.
  517.                CALL    DS:[DI]                 ;Do command subroutine.
  518.                JMP     SHORT FLUSH_END         ;Clear buffer.
  519.  
  520. ;------------------------------------------------;
  521.  
  522. QUOTE_STATE:   CMP     AL,QUOTE_TYPE           ;Is it an ending string quote?
  523.                JNZ     BUFFER_CHAR             ;If no, buffer literal.
  524.                MOV     BX,OFFSET PARAM_STATE   ;Else, back to parameter parsing.
  525.  
  526. ;------------------------------------------------;
  527.  
  528. STORE_STATE:   MOV     ANSI_STATE,BX           ;Store the ANSI state.
  529.  
  530. ;------------------------------------------------;
  531.  
  532. BUFFER_CHAR:   MOV     DI,ESC_COUNT            ;Buffer the character in case
  533.                CMP     DI,ESC_BUFFER_SIZE      ; ending ANSI command is illegal.
  534.                JZ      FLUSH_BUFFER            ;If buffer full, flush.
  535.                ADD     DI,OFFSET ESC_BUFFER    ;Point to next buffer position.
  536.                STOSB                           ;Store the character.
  537.                INC     ESC_COUNT               ;Increment the sequence count.
  538.                RET
  539.  
  540. ;------------------------------------------------;
  541.  
  542. FLUSH_BUFFER:                                     ;$
  543. if PCB                                            ;$
  544.                CALL    BUFFER_CHAR             ;@ Buffer current character also!
  545. FLUSH_BUFF2:                                   ;@
  546. else                                              ;$
  547.                PUSH    AX                      ;Save the current character.
  548. endif                                             ;$
  549.                MOV     SI,OFFSET ESC_BUFFER    ;Point to the sequence buffer.
  550.                MOV     CX,ESC_COUNT            ;Count of buffered characters.
  551. NEXT_FLUSH:    LODSB                           ;Retrieve one.
  552.                PUSH    CX                      ;Save counter and pointer.
  553.                PUSH    SI
  554.                CALL    WRITE_CHAR              ;Write character to screen.
  555.                POP     SI                      ;Restore counter and pointer.
  556.                POP     CX
  557.                LOOP    NEXT_FLUSH              ;Flush entire buffer.
  558. ife PCB                                           ;$
  559.                POP     AX                      ;@Retrieve last character.
  560.                CALL    WRITE_CHAR              ;@Write it also.
  561. endif                                             ;$
  562. FLUSH_END:     MOV     ESC_COUNT,0                   ;Reset counter.
  563.                MOV     ANSI_STATE,OFFSET ESC_STATE   ;Back to Esc state.
  564.                MOV     NUMBER_COUNT,0                ;Reset parameter counter.
  565.                PUSH    CS                            ;Point to our data.
  566.                POP     ES
  567.                MOV     DI,OFFSET NUMBER_BUFFER       ;Clear number buffer
  568.                MOV     CX,ESC_BUFFER_SIZE / 2        ; to zeros.
  569.                XOR     AX,AX
  570.                REP     STOSW
  571.                RET
  572. if PCB                                            ;$
  573. ;------------------------------------------------;@
  574. COLOR_STATE:   CMP     AL,"0"                  ;@ Is it below 0 ?
  575.                JB      FLUSH_BUFFER            ;@ If yes, illegal; flush buffer.
  576.                CMP     AL,"9"                  ;@ Else, is it 0 - 9 ?
  577.                JBE     DO_COLOR                ;@ If yes, Make color.
  578.                CMP     AL,'A'                  ;@ Is it below A ?
  579.                JB      FLUSH_BUFFER            ;@ If yes, illegal; flush buffer.
  580.                CMP     AL,'F'                  ;@ Is it Above F ?
  581.                JA      FLUSH_BUFFER            ;@ If yes, illegal; flush buffer.
  582.                SUB     AL,7                    ;@ Else, adjust for Hex
  583. DO_COLOR:      CALL    ACCUM_COLOR             ;@ Accumulate Color.
  584.                INC     NUMBER_COUNT            ;@ Count the character
  585.                CMP     NUMBER_COUNT,2          ;@ Already got two?
  586. BUFFER_JUMP:   JNE     SHORT BUFFER_CHAR     ;&;@ No, Buffer the character.
  587.                TEST    STATUS,OFF              ;@ Else, is ANSI OFF ?
  588.                JNZ     FLUSH_BUFFER            ;@ If yes, flush Esc, bracket.
  589.                INC     CL                      ;& Is it @XFF restore code?
  590.                JNZ     COLOR_2                 ;& No,  Check for save code
  591.                MOV     CL,SAVE_ATTRIBUTE       ;& Yes, Get back saved attribute
  592.                JMP     SHORT COLOR_3           ;& and set it
  593. COLOR_2:       DEC     CL                      ;& Is it @X00 save code
  594.                JNZ     COLOR_3                 ;& No,  just set it then
  595.                MOV     CL,ATTRIBUTE            ;& Yes, Save the attribute
  596.                MOV     SAVE_ATTRIBUTE,CL       ;&
  597.                JMP     FLUSH_END               ;& and flush it
  598. COLOR_3:       MOV     ATTRIBUTE,CL            ;@ Set Attribute
  599.                JMP     FLUSH_END               ;@ Clear Buffer
  600.  
  601. ;------------------------------------------------;@
  602. VARIABLE_SUB:  CMP     AL,'@'                  ;@ Is it another @
  603.                JB      SHORT_FLUSH             ;@ No, and not valid, so flush
  604.                JNZ     BUFFER_JUMP           ;&;@ No, Buffer the Char (indirect)
  605.                MOV     DX,OFFSET AT_VARIABLE_TABLE ;@ Point to Variable List
  606.                XOR     BX,BX                   ;@ Position in Variable List
  607. NEXT_VARI:     MOV     DI,DX                   ;@ Load DI
  608.                INC     BX                      ;@ Count the Variable
  609.                MOV     SI,OFFSET ESC_BUFFER    ;@ Point to our Variable
  610.                MOV     CX,OFFSET LAST_VARIABLE ;@ Point to End of list
  611.                SUB     CX,DI                   ;@ Minus our current location
  612.                MOV     AL,'@'                  ;@ We need to start on these
  613.                REPNE   SCASB                   ;@ so find one
  614.                JCXZ    SHORT_FLUSH             ;@ End of List? Yes
  615.                MOV     DX,DI                   ;@ No,Save Variable list pointer
  616.                DEC     DI                      ;@ No, Back up to the @
  617.                MOV     CX,ESC_COUNT            ;@ Length of Variable
  618.                REP     CMPSB                   ;@ See if this one matches?
  619.                JNZ     NEXT_VARI               ;@ Didn't match that one!
  620.                CMP     [DI],AL                 ;@ Last Character has to be an @
  621.                JNZ     NEXT_VARI               ;@ Nope
  622.                DEC     BX                      ;@ Back up 1
  623.                CMP     BX,11                   ;@ Is it an Action code
  624.                JA      NOT_ACTION              ;@ No
  625.                SHL     BX,1                    ;@ BX x 2 for proper offset
  626.                MOV     DI,OFFSET JUMP_TABLE    ;@ Point to command table
  627.                ADD     DI,BX                   ;@ Adjust to the desired command
  628.                JMP     EXECUTE                 ;@ Execute the command
  629. NOT_ACTION:    MOV     SI, OFFSET SUB_TABLE    ;@ Point to Sub Table
  630.                MOV     AX,BX                   ;@ Save Variable Number
  631.                MOV     CX,BX                   ;@ Copy Variable Number
  632.                XOR     BX,BX                   ;@ Zero Offset
  633.                XOR     DX,DX                   ;@ Zero out initial length
  634.                SUB     CX,11                   ;@ Adjust Variable Number
  635. NEXT_OFFSET:   ADD     BX,DX                   ;@ Add last Length to Offset
  636.                MOV     DL,[SI]                 ;@ Get Length
  637.                INC     SI                      ;@ Bump the pointer
  638.                LOOP    NEXT_OFFSET             ;@ Do all of them
  639.                MOV     CX,DX                   ;@ Get last Length
  640.                MOV     SI,OFFSET SUB_LIST      ;@ Point to the substitue buffer.
  641.                ADD     SI,BX                   ;@ Add Offset
  642.                SUB     AX,34                   ;@ Is It a String Variable
  643.                JB      IS_STRING               ;@ Yes, Flush our Substitute
  644.                CMP     AX,1                    ;@ Is it Date ot Time?
  645.                JBE     IS_TIMEDATE             ;@ No, It's a Number
  646.                SUB     AX,2                    ;@ Adjust Variable number
  647.                CALL    NUMBER_PARSE            ;@ Create a Numeric value then
  648.                JMP     SHORT VAR_END           ;@ Flush our Number
  649. IS_TIMEDATE:   CALL    MAKE_TIMEDATE           ;@
  650. IS_STRING:     MOV     DI,SI                   ;@ Copy Pointer to DI for SCASB
  651.                MOV     AL,0                    ;@ We look for a Zero
  652.                REPNE   SCASB                   ;@ Findit it
  653.                JNE     GOT_END                 ;@ Skip if we didn't hit a Zero
  654.                DEC     DI                      ;@ Back up if we did
  655. GOT_END:       MOV     CX,DI                   ;@ Get Current Location
  656.                SUB     CX,SI                   ;@ Subtract Starting Location
  657. VAR_END:       JMP     NEXT_FLUSH              ;@ Flush our Substitute
  658.  
  659. SHORT_FLUSH:   PUSH    AX                      ;& Save Character
  660.                CALL    FLUSH_BUFF2             ;@ Flush what we have now
  661.                POP     AX                      ;& Restore Character
  662.                JMP     ESC_STATE               ;& And save the new state
  663.  
  664. ;------------------------------------------------;@
  665. ATX_STATE:     MOV     BX,OFFSET COLOR_STATE   ;@ Assume 'X' Character
  666.                CMP     AL,"X"                  ;@ Is it X? If yes, store
  667.                JZ      SHORT_STORE             ;@ char. and next state.
  668.                CMP     AL,'@'                  ;@ Is it another '@' already?
  669.                JZ      WRITE_CHAR              ;@ Yes!
  670.                CMP     AL,ESC_CHAR             ;& Is it an Escape
  671.                JE      SHORT_FLUSH             ;& Yes, so flush buffer & restart
  672.                MOV     BX,OFFSET VARIABLE_SUB  ;@ No, Must be a Variable
  673. SHORT_STORE:   JMP     STORE_STATE             ;@ Store the state
  674. endif                                             ;$
  675. ;------------------------------------------------;
  676. ; Slow video writes are via BIOS Write TTY.      ;
  677. ;------------------------------------------------;
  678.  
  679. WRITE_CHAR:    CMP     AL,BELL                 ;Let BIOS process BS and BELL.
  680.                JZ      WRITE_TTY
  681.                CMP     AL,BS
  682.                JZ      WRITE_TTY
  683.  
  684.                CALL    GET_BIOS_DATA           ;Get BIOS video data.
  685.                CMP     AL,TAB                  ;Is character a TAB?
  686.                JNZ     CK_ACTIVE               ;If no, process normally.
  687.                MOV     CX,CURSOR_POSN          ;Else, expand TAB to
  688.                AND     CX,7                    ; appropriate space characters.
  689.                NEG     CX
  690.                ADD     CX,8
  691. NEXT_TAB:      PUSH    CX
  692.                MOV     AL,SPACE
  693.                CALL    CK_ACTIVE
  694.                POP     CX
  695.                LOOP    NEXT_TAB
  696.                RET
  697.  
  698. CK_ACTIVE:     TEST    STATUS,OFF              ;Is ANSI OFF?
  699.                JNZ     WRITE_TTY               ;If yes, write via BIOS TTY.
  700. CK_FAST:       CALL    CK_SLOW_TEXT            ;Is ANSI SLOW or in graphics
  701.                JNC     WRITE_FAST              ; mode? If no, write fast.
  702.  
  703.                CMP     AL,CR                   ;Let BIOS handle CR and LF.
  704.                JZ      WRITE_TTY
  705.                CMP     AL,LF
  706.                JZ      WRITE_TTY
  707.  
  708. WRITE_SLOW:    PUSH    AX                      ;Else, write character/attribute
  709.                MOV     CX,1                    ; at current cursor position
  710.                MOV     BH,ACTIVE_PAGE          ; via BIOS.
  711.                MOV     BL,ATTRIBUTE
  712.                MOV     AH,9
  713.                INT     10H
  714.                POP     AX
  715.  
  716.                CMP     LINE_WRAP,ON            ;Is line wrap on?
  717.                JZ      TTY                     ;If yes, continue.
  718.                MOV     CX,CRT_COLS             ;Else, cursor at rightmost
  719.                DEC     CL                      ; column?
  720.                CMP     CL,CURSOR_COL           ;If yes, continue, else
  721.                JNZ     TTY                     ; return without writing.
  722.                RET
  723.  
  724. ;------------------------------------------------;
  725.  
  726. WRITE_TTY:     MOV     BL,7                    ;Attribute in graphics mode.
  727. TTY:           MOV     AH,0EH
  728.                INT     10H
  729.                RET
  730.  
  731. ;----------------------------------------------------------------------------;
  732. ; Fast screen writes are directly to the video buffer without retrace check. ;
  733. ;----------------------------------------------------------------------------;
  734.  
  735. WRITE_FAST:    PUSH    ES                      ;Preserve extra segment.
  736.                MOV     DX,CURSOR_POSN          ;Retrieve cursor position.
  737.                CMP     AL,CR                   ;Carriage return?
  738.                JNZ     CK_LINEFEED             ;If no, check linefeed.
  739.                XOR     DL,DL                   ;Else, cursor to first column.
  740.                JMP     SHORT UPDATE_CURSOR
  741. CK_LINEFEED:   CALL    VIDEO_SETUP             ;Calculate video address.
  742.                CMP     AL,LF                   ;Linefeed?
  743.                JZ      NEXT_ROW                ;If yes, next row.
  744.  
  745.                MOV     AH,ATTRIBUTE            ;Retrieve attribute.
  746.                STOSW                           ;Put char/attrib in video buffer.
  747.                INC     DL                      ;Increment cursor column.
  748.                CMP     DL,BYTE PTR CRT_COLS    ;End of row?
  749.                JB      UPDATE_CURSOR           ;If no, update cursor.
  750.  
  751.                CMP     LINE_WRAP,OFF           ;Else, line wrap off?
  752.                JZ      FAST_END                ;If yes, don't move cursor.
  753.                XOR     DL,DL                   ;Else, column zero.
  754. NEXT_ROW:      INC     DH                      ;Next row.
  755.                CALL    INFORMATION             ;Get displayable row info.
  756.                CMP     DH,AL                   ;Beyond the bottom of screen?
  757.                JBE     UPDATE_CURSOR           ;If no, update cursor.
  758.  
  759.                DEC     DH                      ;Else, cursor to original row.
  760.                MOV     AX,CRT_COLS             ;. Get number of columns
  761.                PUSH    DX                      ;. Save Cursor position
  762.                PUSH    AX                      ;. Save Columns
  763.                SHL     AX,1                    ;. Twice for Char/Attribute
  764.                MOV     SI,AX                   ;. Starting offset in SI
  765.                MOV     DL,START_SCROLL         ;. Where we allow scroll to start
  766.                MUL     DL                      ;. Calculate offset in AX
  767.                SUB     DH,DL                   ;. Reduce line count
  768.                MOV     DI,CRT_START            ;Point destination to top.
  769.                ADD     DI,AX                   ;. Add offset
  770.                ADD     SI,DI                   ;. Point source to second row
  771.                POP     AX                      ;. Get Back Columns
  772.                PUSH    AX                      ;. Save it again
  773.                MUL     DH                      ;Times displayable rows - 1.
  774.                MOV     CX,AX                   ; equals char/attrib to scroll.
  775.                PUSH    DS                      ;Save data segment and
  776.                PUSH    ES                      ; point to video segment.
  777.                POP     DS
  778.                REP     MOVSW                   ;Scroll the screen.
  779.                POP     DS                      ;Restore data segment.
  780.                POP     CX                      ;Retrieve CRT columns.
  781.                POP     DX                      ;.Get back Cursor info
  782.                MOV     AL,SPACE                ;Write space/attrib to
  783.                MOV     AH,ATTRIBUTE            ; bottom row.
  784.                REP     STOSW
  785.  
  786. UPDATE_CURSOR: CALL    SET_CURSOR              ;Update the cursor position.
  787. FAST_END:      POP     ES                      ;Restore extra segment.
  788.                RET
  789. if PCB                                            ;$
  790. ;@************ SUPPORT ROUTINES *************;
  791.  
  792. QOFF:          MOV     AL,0FFH                 ;& Show QOFF
  793.                JMP     SHORT QON2              ;&
  794. QON:           XOR     AL,AL                   ;& Show QON
  795. QON2:          MOV     Q_STATE,AL              ;& Store the state
  796.                RET                             ;& All done
  797.  
  798. BEEP:          MOV     AL,7                    ;@
  799.                JMP     WRITE_CHAR              ;@
  800. MORE:          MOV     AX,MORE_DELAY           ;@
  801.                JMP     SHORT PAUSE2            ;@
  802. PAUSE:         MOV     AX,PAUSE_DELAY          ;@
  803. PAUSE2:        CMP     Q_STATE,0               ;& Are we at a QOFF state
  804.                JNZ     WAIT1                   ;& Yes, then these are WAITs
  805.                MOV     SI,OFFSET MORE_PROMPT   ;@ Point to More? Prompt
  806.                MOV     CX,MORE_LENGTH          ;@ Get the Length of it
  807.                JMP     SHORT WAIT2             ;@ Go Wait
  808. WAIT1:         MOV     AX,WAIT_DELAY           ;@
  809.                MOV     SI,OFFSET WAIT_PROMPT   ;@ Point to Wait Prompt
  810.                MOV     CX,WAIT_LENGTH          ;@ Get the Length of it
  811. WAIT2:         MOV     PAUSE_TIMER,AX          ;@
  812. ;               PUSH    CX                      ;@ Save Length
  813. WAIT2_LOOP:    LODSB                           ;@ Get Character
  814.                PUSH    CX                      ;@
  815.                PUSH    SI                      ;@
  816.                CALL    WRITE_CHAR              ;@ Output it
  817.                POP     SI                      ;@
  818.                POP     CX                      ;@
  819.                LOOP    WAIT2_LOOP              ;@ Do all the Characters
  820. WAIT_LOOP:     MOV     AH,1                    ;@ KeyBoard Status
  821.                INT     16H                     ;@ Keyboard I/O Services
  822.                JNZ     CONTINUE                ;@ Key Hit!
  823.                CMP     PAUSE_TIMER,0           ;@ Timer Run out?
  824.                JNE     WAIT_LOOP               ;@ No
  825.                JMP     SHORT WAIT3             ;@ Yes
  826. CONTINUE:      MOV     AH,0                    ;@ KeyBoard Read
  827.                INT     16H                     ;@ Keyboard I/O Services
  828. WAIT3:                                         ;@
  829.                XOR     CL,CL                   ;@ Clear the Attribute
  830.                XCHG    CL,ATTRIBUTE            ;&  and
  831.                PUSH    CX                      ;&    save it too
  832.                MOV     DX,CURSOR_POSN          ;& Get Cursor
  833.                MOV     DL,0                    ;& First column
  834.                CALL    SET_CURSOR              ;& Set the new Cursor
  835.                CALL    ERASE_2                 ;& Erase the line
  836. ;&
  837. ;& The following lines (and the PUSH CX above) will clear only the PROMPT
  838. ;& and leave the cursor where it was when the prompt appears. This was
  839. ;& different than PCBoard 14.5 so I changed it to clear the entire line
  840. ;& via the above four lines. Left the old code in case someome wanted it.
  841. ;&
  842. ;&               POP     CX                      ;@ Get back Length
  843. ;&ERASE_LOOP:    PUSH    CX                      ;@ Save it again
  844. ;&               MOV     AL,BS                   ;@ Send BS
  845. ;&               CALL    WRITE_CHAR              ;@  character
  846. ;&               MOV     AL,' '                  ;@  and then space
  847. ;&               CALL    WRITE_CHAR              ;@  character to erase
  848. ;&               MOV     AL,BS                   ;@  then BS again
  849. ;&               CALL    WRITE_CHAR              ;@  to backup.
  850. ;&               POP     CX                      ;@ get back length again
  851. ;&               LOOP    ERASE_LOOP              ;@ Erase entire prompt.
  852.                POP     CX                      ;& Restore
  853.                MOV     ATTRIBUTE,CL            ;&  the Attribute
  854.                RET                             ;@
  855. AUTOOFF:       MOV     AX,WAIT_DELAY           ;@ Restore More to a Wait
  856.                JMP     SHORT AUTO2             ;@
  857. AUTOMORE:      MOV     AX,PAUSE_DELAY          ;@ Make More a Pause
  858. AUTO2:         MOV     MORE_DELAY,AX           ;@
  859. SKIP_IT:       RET                             ;@
  860. endif                                             ;$
  861. ;************* SUPPORT ROUTINES *************;
  862.  
  863. CK_QUOTE:      MOV     BX,OFFSET QUOTE_STATE   ;Assume quote state.
  864.                MOV     AH,DOUBLE_QUOTE
  865.                CMP     AL,AH                   ;Is it double quote?
  866.                JZ      GOT_QUOTE               ;If yes, string delimiter.
  867.                MOV     AH,SINGLE_QUOTE         ;Is it single quote?
  868.                CMP     AL,AH                   ;Is yes, string delimiter.
  869.                JNZ     QUOTE_END               ;Else, return ZR = 0.
  870. GOT_QUOTE:     MOV     QUOTE_TYPE,AH           ;Store as matching string end.
  871. QUOTE_END:     RET
  872.  
  873. ;------------------------------------------------;
  874.  
  875. ACCUMULATE:    PUSH    AX                      ;Preserve number character.
  876.                SUB     AL,"0"                  ;Convert ASCII to binary.
  877.                MOV     CL,AL                   ;Save the number.
  878.                MOV     AX,10                   ;Multiply previous count by 10.
  879.                MOV     BX,NUMBER_COUNT
  880.                MUL     BYTE PTR NUMBER_BUFFER[BX]
  881.                ADD     AL,CL                            ;Add in new number
  882.                MOV     BYTE PTR NUMBER_BUFFER[BX],AL    ; and store.
  883.                POP     AX
  884.                RET
  885. if PCB                                            ;$
  886. ;------------------------------------------------;@
  887.  
  888. ACCUM_COLOR:   PUSH    AX                      ;@ Preserve number character.
  889.                SUB     AL,"0"                  ;@ Convert ASCII to hex
  890.                MOV     AH,BYTE PTR NUMBER_BUFFER ;@ Get current number
  891.                SHL     AH,1                      ;@ Shift left 4 bits
  892.                SHL     AH,1                      ;@
  893.                SHL     AH,1                      ;@
  894.                SHL     AH,1                      ;@
  895.                OR      AH,AL                     ;@ Add in new number
  896.                MOV     BYTE PTR NUMBER_BUFFER,AH ;@ and store.
  897.                MOV     CL,AH                     ;@ Return with Color in CL
  898.                POP     AX                        ;@
  899.                RET                               ;@
  900.  
  901. NUMBER_PARSE:  MOV  BX,[SI]                 ;@ Get low word
  902.                MOV  DX,AX                   ;@ Save Variable Number
  903.                XOR  AX,AX                   ;@ Assume Integer
  904.                CMP  CX,4                    ;@ Is that a Long Integer?
  905.                JNE  SHORT_INT               ;@ No, Integer
  906.                MOV  AX,[SI + 2]             ;@ Yes, Get high word
  907. SHORT_INT:     MOV  DI, OFFSET PARSE_BUFFER ;@ Point DI at number space
  908.                MOV  CX,10                   ;@ Set divisor to 10
  909.                XOR  SI,SI                   ;@ Clear SI as counter
  910.                MOV  COMMA,2                 ;@ Assume a Ratio
  911.                CMP  DX,2                    ;@ Is it a Ratio?
  912.                JB   GETDIGIT                ;@ No
  913. RESET_COMMA:   MOV  COMMA,4                 ;@ Set Comma Counter
  914. GETDIGIT:      DEC  DI                      ;@ Point DI at correct character
  915.                INC  SI                      ;@ Register that we have a character
  916.                DEC  COMMA                   ;@ Do we need a Comma?
  917.                JNZ  NO_COMMA                ;@ No
  918.                MOV  BYTE PTR [DI],','       ;@ Yes, So Put one in!
  919.                JMP  RESET_COMMA             ;@ And restart the Comma count.
  920. NO_COMMA:      XOR  DX,DX                   ;@ Clear DX to take remainder
  921.                DIV  CX                      ;@ Divide AX first (High word)
  922.                MOV  BP,AX                   ;@ Save quotient
  923.                MOV  AX,BX                   ;@ Get low word
  924.                DIV  CX                      ;@ DX had leftover from first divide
  925.                MOV  BX,AX                   ;@ Save quotient
  926.                MOV  AX,BP                   ;@ Put high word back
  927.                ADD  DL,30h                  ;@ Make it an ASCII digit from remainder
  928.                MOV  [DI],DL                 ;@ Put it in our string
  929.                OR   AX,AX                   ;@ Is high word zero?
  930.                JNZ  GETDIGIT                ;@ No keep going
  931.                OR   BX,BX                   ;@ Is low word zero?
  932.                JNZ  GETDIGIT                ;@ No keep going
  933.                MOV  CX,SI                   ;@ Digit count to CX
  934.                MOV  SI,DI                   ;@ String Pointer to SI
  935.                MOV  DI, OFFSET PARSE_BUFFER ;@ Point DI at number space
  936.                CMP  BYTE PTR [DI][-2],','   ;@ Was it a Ratio
  937.                JNE  NOT_RATIO               ;@ No, nevermind
  938.                MOV  BYTE PTR [DI][-2],'.'   ;@ Change comma to Decimal
  939.                MOV  BYTE PTR [DI],":"       ;@ Yes, Add ':1' to it
  940.                MOV  BYTE PTR [DI][1],"1"    ;@
  941.                ADD  CX,2                    ;@ Account for two more characers
  942. NOT_RATIO:     RET                          ;@
  943.  
  944. MAKE_TIMEDATE: MOV  DI, OFFSET NUMBER_BUFFER ;@ Point to Number Buffer
  945.                MOV  SI,DI            ;@ Save it in SI too
  946.                JE   MAKE_TIME        ;@ It was TIME on Entry!
  947.                MOV  CX,8             ;@ It was DATE! Length = 8
  948.                PUSH CX               ;@ Save Length
  949.                MOV  AH,04H           ;@ Get date service
  950.                INT  1AH              ;@ Call BIOS - return codes as follows:
  951.                PUSH CX               ;@ CH = Century (19-20)  CL = Year (00-99)
  952.                PUSH DX               ;@ DH = Month   (1-12)   DL = Day  (00-31)
  953.                MOV  AL,DH            ;@ Month
  954.                CALL ASCII            ;@ Convert byte to ASCII digits
  955.                MOV  AL,'-'           ;@
  956.                STOSB                 ;@
  957.                POP  AX               ;@ Day - was DX when pushed
  958.                CALL ASCII            ;@ Convert byte to ASCII digits
  959.                MOV  AL,'-'           ;@
  960.                STOSB                 ;@
  961.                POP  AX               ;@ Year - was CX when pushed
  962.                POP  CX               ;@ Restore Length
  963.                JMP  SHORT ASCII      ;@ Convert byte to ASCII digit
  964.  
  965. MAKE_TIME:     MOV  CX,5             ;@ Length = 5
  966.                PUSH CX               ;@ Save Length
  967.                MOV  AH,02H           ;@ Get time service
  968.                INT  1AH              ;@ Call BIOS - return codes as follows:
  969.                PUSH CX               ;@ CH = Hours   (0-23)   CL = Minutes (0-59)
  970.                MOV  AL,CH            ;@ Hours
  971.                CALL ASCII            ;@ Convert byte to ASCII digits
  972.                MOV  AL,':'           ;@
  973.                STOSB                 ;@
  974.                POP  AX               ;@ Minutes - was CX when pushed
  975.                POP  CX               ;@ Restore Length
  976. ASCII:         MOV  AH,AL            ;@ Need to get BCD Digits
  977.                SHR  AL,1             ;@  MSD in AL
  978.                SHR  AL,1             ;@   lower
  979.                SHR  AL,1             ;@     4
  980.                SHR  AL,1             ;@     Bits
  981.                AND  AH,0FH           ;@ And LSD in AH cleanly
  982.                OR   AX,3030H         ;@ Convert to ASCII
  983.                STOSW                 ;@ Stuff Digits into Buffer (in reverse)
  984.                RET                   ;@ SI Points to String Data
  985. endif                                   ;$
  986. ;---------------------------------------------------------------------------;
  987. ; OUTPUT:  CY = 1 if write SLOW mode or in graphics mode; CY = 0 otherwise. ;
  988. ;---------------------------------------------------------------------------;
  989.  
  990. CK_SLOW_TEXT:  TEST    STATUS,SLOW
  991.                JNZ     SLOW_MODE
  992.                CMP     CRT_MODE,7
  993.                JZ      TEXT_MODE
  994.                CMP     CRT_MODE,3
  995.                JA      SLOW_MODE
  996. TEXT_MODE:     CLC
  997.                RET
  998.  
  999. SLOW_MODE:     STC
  1000.                RET
  1001.  
  1002. ;-------------------------------------;
  1003. ; OUTPUT:  AL = Screen rows minus one ;
  1004. ;-------------------------------------;
  1005.  
  1006. INFORMATION:   PUSH    DS                      ;Save data segment.
  1007.                MOV     AX,40H                  ;Point to BIOS data.
  1008.                MOV     DS,AX
  1009.                MOV     AL,DS:[84H]             ;Retrieve rows - 1.
  1010.                OR      AL,AL                   ;BIOS supported?
  1011.                JNZ     INFO_END                ;If yes, done here.
  1012.                MOV     AL,24                   ;Else, assume 25 lines.
  1013. INFO_END:      POP     DS
  1014.                RET
  1015.  
  1016. ;------------------------------------------------------------------------------;
  1017. ; INPUT:  DX = Cursor position.                                                ;
  1018. ; OUTPUT: ES = Video buffer segment; DI = Video buffer offset; AX,DX preserved ;
  1019. ;------------------------------------------------------------------------------;
  1020.  
  1021. VIDEO_SETUP:   PUSH    AX
  1022.                MOV     AX,CRT_COLS             ;Retrieve CRT columns.
  1023.                MUL     DH                      ;Times cursor row.
  1024.                MOV     BL,DL
  1025.                XOR     BH,BH
  1026.                ADD     AX,BX                   ;Plus cursor column.
  1027.                SHL     AX,1                    ;Times two for attribute.
  1028.                MOV     DI,CRT_START            ;Plus starting video offset.
  1029.                ADD     DI,AX                   ;Equals destination.
  1030.  
  1031.                MOV     BX,0B000H               ;Assume mono card.
  1032.                CMP     ADDR_6845,3B4H          ;Is it mono port?
  1033.                JZ      VIDEO_SEGMENT           ;If yes, guessed right.
  1034.                ADD     BX,800H                 ;Else, point to color segment.
  1035. VIDEO_SEGMENT: MOV     ES,BX
  1036.                POP     AX
  1037.                RET
  1038.  
  1039. ;------------------------------------------------;
  1040. ; Move BIOS video data into our data segment.    ;
  1041. ;------------------------------------------------;
  1042.  
  1043. GET_BIOS_DATA: PUSH    DS
  1044.                PUSH    DI                      ;Point to BIOS data segment.
  1045.                MOV     BX,40H
  1046.                MOV     DS,BX
  1047.                MOV     SI,BIOS_ACTIVE_PAGE     ;Start with active page.
  1048.                MOV     DI,OFFSET ACTIVE_PAGE
  1049.                MOVSB                           ;Retrieve active page
  1050.                MOVSW                           ; and address of 6845 port.
  1051.                MOV     SI,BIOS_CRT_MODE        ;Retrieve CRT mode, CRT columns,
  1052.                MOV     CX,CRT_DATA_LENGTH      ; CRT length, CRT start.
  1053.                REP     MOVSB
  1054.                MOV     BL,ES:ACTIVE_PAGE       ;Use active page as index
  1055.                XOR     BH,BH                   ; of active cursor position.
  1056.                SHL     BX,1
  1057.                ADD     SI,BX
  1058.                MOVSW
  1059.                POP     DI
  1060.                POP     DS
  1061.                RET
  1062.  
  1063. ;----------------------------------------------------------------------------;
  1064. ; OUTPUT: BL = First parameter; BH = Second parameter; DX = cursor position. ;
  1065. ;----------------------------------------------------------------------------;
  1066.  
  1067. ADJUST_NUMBER: MOV     BX,WORD PTR NUMBER_BUFFER
  1068.                OR      BH,BH
  1069.                JNZ     ADJUST_AL               ;If either parameter zero,
  1070.                INC     BH                      ; increment to convert
  1071. ADJUST_AL:     OR      BL,BL                   ; to base one.
  1072.                JNZ     ADJUST_END
  1073.                INC     BL
  1074. ADJUST_END:    MOV     DX,CURSOR_POSN          ;Return cursor position.
  1075.                RET
  1076.  
  1077. ;--------------------------------------------------------------------------;
  1078. ; INPUT:  AX = number; BP = 0 if console output; BP = 1 if storage output. ;
  1079. ;--------------------------------------------------------------------------;
  1080.  
  1081. DECIMAL_OUT:   MOV     BX,10                   ;Divisor of ten.
  1082.                XOR     CX,CX                   ;Zero in counter.
  1083. NEXT_COUNT:    XOR     DX,DX                   ;Zero in high half.
  1084.                DIV     BX                      ;Divide by ten.
  1085.                ADD     DL,"0"                  ;Convert to ASCII.
  1086.                PUSH    DX                      ;Save results.
  1087.                INC     CX                      ;Also increment count.
  1088.                CMP     AX,0                    ;Are we done?
  1089.                JNZ     NEXT_COUNT              ;Continue until zero.
  1090.                OR      BP,BP                   ;If BP zero, output to screen.
  1091.                JNZ     DEVICE_OUTPUT           ;Else, store in buffer.
  1092.  
  1093. REPORT_OUTPUT: POP     AX                      ;Retrieve number.
  1094.                CALL    PRINT_CHAR              ;Display it.
  1095.                LOOP    REPORT_OUTPUT
  1096.                RET
  1097.  
  1098. DEVICE_OUTPUT: CMP     CX,2                    ;Two digits?
  1099.                JZ      TWO_DIGITS              ;If yes, process normally.
  1100.                MOV     AL,"0"                  ;Else, store leading zero.
  1101.                STOSB
  1102.  
  1103. TWO_DIGITS:    POP     AX                      ;Retrieve number.
  1104.                STOSB                           ;Store it
  1105.                LOOP    TWO_DIGITS
  1106.                RET
  1107.  
  1108. ;************* ANSI COMMAND SUBSET *************;
  1109.  
  1110. CLS:           MOV     BH,7                    ;Assume normal attribute.
  1111.                MOV     BL,BYTE PTR CRT_MODE    ;Get current video mode.
  1112.                CMP     BL,4
  1113.                JBE     CK_CLS_STATUS           ;If text mode then check if
  1114.                CMP     BL,7                    ; ANSI active.
  1115.                JZ      CK_CLS_STATUS
  1116.                XOR     BH,BH                   ;Else, use black attribute
  1117.                TEST    STATUS,OFF
  1118.                JNZ     CLS_SLOW                ;If ANSI inactive, via BIOS.
  1119.                JMP     SHORT CK_CLS_SLOW       ;Else, check if FAST or SLOW.
  1120.  
  1121. CK_CLS_STATUS: TEST    STATUS,OFF              ;Is ANSI OFF?
  1122.                JNZ     CLS_SLOW                ;If yes, CLS via BIOS.
  1123.                MOV     BH,ATTRIBUTE            ;Else, current attribute.
  1124. CK_CLS_SLOW:   CALL    CK_SLOW_TEXT
  1125.                JC      CLS_SLOW                ;If ANSI SLOW, via BIOS.
  1126.  
  1127. CLS_FAST:      MOV     AH,BH                   ;Else, attribute in high half.
  1128.                MOV     AL,SPACE                ;Space character in low half.
  1129.                XOR     DX,DX                   ;Cursor position home.
  1130.                MOV     DH,START_SCROLL         ;$ protect lines
  1131.                CALL    VIDEO_SETUP             ;Calculate video address.
  1132.                MOV     CX,CRT_LEN              ;Retrieve CRT length.
  1133.                SHR     CX,1                    ;Times two for attribute.
  1134.                REP     STOSW                   ;Write directly to video buffer.
  1135.                JMP     SHORT SET_CURSOR        ;Set the cursor top left corner.
  1136.  
  1137. CLS_SLOW:      CALL    INFORMATION             ;Get displayable rows.
  1138.                MOV     DH,AL                   ;Store in DH.
  1139.                MOV     DL,BYTE PTR CRT_COLS    ;Retrieve CRT columns.
  1140.                DEC     DL                      ;Adjust to zero base.
  1141.                XOR     CX,CX                   ;Scroll active page.
  1142.                MOV     AX,600H
  1143.                INT     10H
  1144.                XOR     DX,DX                   ;Home the cursor.
  1145.                JMP     SHORT SET_CURSOR
  1146.  
  1147. ;------------------------------------------------;
  1148. CURS_POSITION:                                 ;These two commands are the same.
  1149. HORZ_VERT_POS: CALL    INFORMATION             ;Returns AL = screen rows.
  1150.                CALL    ADJUST_NUMBER           ;Returns BL,BH = parameters.
  1151.                SUB     BX,101H                 ;Zero based.
  1152.                CMP     BL,AL                   ;If cursor request within
  1153. ;$             JA      CURSOR_END              ; boundaries of screen, set it.
  1154.                JBE     ROWOK                   ;$boundaries of screen, set it.
  1155.                MOV     BL,AL                   ;$Set to last row
  1156. ROWOK:         CMP     BH,BYTE PTR CRT_COLS    ;$
  1157. ;$             JAE     CURSOR_END
  1158.                JB      COLOK                   ;$
  1159.                MOV     BH,BYTE PTR CRT_COLS    ;$Set to
  1160.                DEC     BH                      ;$       last column
  1161. COLOK:         XCHG    BH,BL                   ;
  1162.                MOV     DX,BX
  1163.  
  1164. SET_CURSOR:    MOV     BH,ACTIVE_PAGE          ;Set cursor via BIOS.
  1165.                MOV     AH,2
  1166.                INT     10H
  1167. CURSOR_END:    RET
  1168.  
  1169. ;------------------------------------------------;
  1170.  
  1171. CURSOR_UP:     CALL    ADJUST_NUMBER           ;Move cursor up one or more rows
  1172.                OR      DH,DH                   ; without changing column.
  1173.                JZ      CURSOR_END              ;If already at top, ignore.
  1174.                SUB     DH,BL
  1175.                JNC     SET_CURSOR              ;Stay in bounds.
  1176.                XOR     DH,DH
  1177.                JMP     SHORT SET_CURSOR
  1178.  
  1179. ;------------------------------------------------;
  1180.  
  1181. CURSOR_DOWN:   CALL    INFORMATION             ;Returns AL = screen rows.
  1182.                CALL    ADJUST_NUMBER           ;Returns BL,BH =nos.; DX = cursor
  1183.                CMP     DH,AL                   ;Move cursor down requested
  1184.                JZ      CURSOR_END              ; rows without changing column.
  1185.                ADD     DH,BL
  1186.                CMP     DH,AL
  1187.                JNA     SET_CURSOR
  1188.                MOV     DH,AL                   ;Stay in bounds.
  1189.                JMP     SHORT SET_CURSOR
  1190.  
  1191. ;------------------------------------------------;
  1192.  
  1193. CURS_FORWARD:  CALL    ADJUST_NUMBER           ;Returns BL,BH =nos.; DX = cursor
  1194.                MOV     BH,BYTE PTR CRT_COLS    ;Retrieve displayable columns.
  1195.                DEC     BH                      ;Adjust to zero base.
  1196.                CMP     DL,BH                   ;Move cursor forward one or more
  1197.                JZ      CURSOR_END              ; columns without changing row.
  1198.                ADD     DL,BL
  1199.                CMP     DL,BH
  1200.                JNA     SET_CURSOR
  1201.                MOV     DL,BH                   ;Stay in bounds.
  1202.                JMP     SHORT SET_CURSOR
  1203.  
  1204. ;------------------------------------------------;
  1205.  
  1206. CURS_BACKWARD: CALL    ADJUST_NUMBER           ;Returns BL,BH =nos.; DX = cursor
  1207.                OR      DL,DL                   ;Move cursor backward one or
  1208.                JZ      CURSOR_END              ; more columns without changing
  1209.                SUB     DL,BL                   ; row.  Ignore if already left.
  1210.                JNC     SET_CURSOR
  1211.                XOR     DL,DL                   ;Stay in bounds.
  1212.                JMP     SHORT SET_CURSOR
  1213.  
  1214. ;--------------------------------------------------------;
  1215. ; Report cursor position via console; Format: ESC[#;#R   ;
  1216. ;--------------------------------------------------------;
  1217.  
  1218. DEVICE_STATUS: MOV     DI,OFFSET DEVICE_STATUS_BUFFER
  1219.                MOV     AL,ESC_CHAR
  1220.                STOSB                           ;Store leading Esc, bracket
  1221.                MOV     AL,"["                  ;in special Device Status Buffer.
  1222.                STOSB
  1223.  
  1224.                MOV     AL,CURSOR_ROW           ;Retrieve cursor row.
  1225.                XOR     AH,AH                   ;Zero in high half.
  1226.                INC     AX                      ;Convert to base one.
  1227.                MOV     BP,1                    ;Flag as storage.
  1228.                CALL    DECIMAL_OUT             ;Convert to ASCII.
  1229.                MOV     AL,";"                  ;Store delimiting semi-colon.
  1230.                STOSB
  1231.                MOV     AL,CURSOR_COL           ;Do same with cursor column.
  1232.                XOR     AH,AH
  1233.                INC     AX
  1234.                CALL    DECIMAL_OUT
  1235.                MOV     AL,"R"                  ;Add command character
  1236.                STOSB
  1237.                MOV     AL,CR                   ; and carriage return.
  1238.                STOSB
  1239.                SUB     DI,OFFSET DEVICE_STATUS_BUFFER   ;Setup for console out.
  1240.                MOV     REASSIGN_COUNT,DI
  1241.                MOV     REASSIGN_POS,OFFSET DEVICE_STATUS_BUFFER
  1242.                MOV     REASSIGN_FLAG,ON
  1243.                MOV     REMOVE_FLAG,OFF
  1244.                RET
  1245.  
  1246. ;------------------------------------------------;
  1247.  
  1248. SAVE_CURSOR:   MOV     DX,CURSOR_POSN
  1249.                MOV     SAVE_POSITION,DX
  1250.                RET
  1251.  
  1252. ;------------------------------------------------;
  1253.  
  1254. RESTORE_CURS:  MOV     DX,SAVE_POSITION
  1255.                JMP     SET_CURSOR
  1256.  
  1257. ;------------------------------------------------;
  1258.  
  1259. ERASE_IN_LINE: MOV     DX,CURSOR_POSN          ;Erase from the cursor to
  1260. ERASE_2:       MOV     CX,CRT_COLS             ;& the end of the line, including
  1261.                SUB     CL,DL                   ; the current cursor position.
  1262.                CALL    CK_SLOW_TEXT
  1263.                JC      ERASE_SLOW              ;If ANSI ON and not graphics,
  1264.                CALL    VIDEO_SETUP             ; write directly to video buffer
  1265.                MOV     AL,SPACE                ; with space/attribute.
  1266.                MOV     AH,ATTRIBUTE
  1267.                REP     STOSW
  1268.                RET
  1269.  
  1270. ERASE_SLOW:    MOV     CX,DX                   ;Else, erase SLOW via
  1271.                MOV     DL,BYTE PTR CRT_COLS    ; BIOS scroll active page.
  1272.                DEC     DL
  1273.                MOV     BH,ATTRIBUTE
  1274.                MOV     AX,601H
  1275.                INT     10H
  1276.                RET
  1277.  
  1278. ;------------------------------------------------;
  1279. ;            Set Graphics Rendition              ;
  1280. ;------------------------------------------------;
  1281.  
  1282. SGR:           MOV     SI,OFFSET NUMBER_BUFFER     ;Point to number parameters.
  1283. NEXT_SGR:      LODSB                               ;Retrieve parameter.
  1284.                MOV     DI,OFFSET ATTRIBUTE_TABLE   ;Look up attribute in
  1285.                MOV     CX,ATTRIBUTE_LENGTH         ; translation table.
  1286.                REPNZ   SCASB
  1287.                JNZ     SGR_LOOP
  1288.  
  1289.                MOV     DI,OFFSET ATTRIBUTE_END
  1290.                SHL     CX,1
  1291.                SUB     DI,CX
  1292.                MOV     AX,[DI]
  1293.                AND     ATTRIBUTE,AL            ;If match, AND with strip mask.
  1294.                OR      ATTRIBUTE,AH            ;OR with add mask.
  1295. SGR_LOOP:      DEC     NUMBER_COUNT            ;Do all parameters.
  1296.                JNZ     NEXT_SGR
  1297.                RET
  1298.  
  1299. ;------------------------------------------------;
  1300.  
  1301. SET_MODE:      MOV     AH,ON                   ;Assume command 7,
  1302.                JMP     SHORT CK_WRAP           ; turn line wrap on.
  1303.  
  1304. ;------------------------------------------------;
  1305.  
  1306. RESET_MODE:    MOV     AH,OFF                     ;Assume turn line wrap off.
  1307. CK_WRAP:       MOV     AL,BYTE PTR NUMBER_BUFFER  ;Retrieve number parameter.
  1308.                CMP     AL,7                       ;Is it 7?
  1309.                JZ      SET_WRAP                ;If yes, set wrap mode.
  1310.                JB      DO_MODE                 ;1 - 6 valid modes.
  1311.                CMP     AL,14                   ;14 - 16 valid modes.
  1312.                JB      MODE_END
  1313.                CMP     AL,19
  1314.                JA      MODE_END                ;If above 16, illegal.
  1315. DO_MODE:       XOR     AH,AH                   ;Else, set video mode
  1316.                INT     10H                     ; to parameter.
  1317.                RET
  1318.  
  1319. SET_WRAP:      MOV     LINE_WRAP,AH
  1320. MODE_END:      RET
  1321.  
  1322. ;--------------------------------------------------------------------;
  1323. ; Keyboard Key Reassignment:  First convert ASCII numbers to binary, ;
  1324. ; parse out delimiting semi-colons, and quote string delimiters.     ;
  1325. ;--------------------------------------------------------------------;
  1326.  
  1327. REASSIGNMENT:  TEST    STATUS,POFF             ;:If assignment are OFF,
  1328.                JZ      NOT_POFF                ;:   then exit as if
  1329.                JMP     ASSIGN_FLUSH            ;:   we are out of room.
  1330. NOT_POFF:                                      ;:
  1331.                MOV     CX,ESC_COUNT            ;Retrieve length of Esc sequence.
  1332.                DEC     CX                          ;Adjust.
  1333.                MOV     SI,OFFSET ESC_BUFFER + 2    ;Point past Esc, bracket.
  1334.                MOV     DI,OFFSET PARSE_BUFFER      ;Point to parse storage.
  1335. NEXT_STRING:   MOV     QUOTE_TYPE,0                ;Reset quote type.
  1336. NEXT_NUM:      XOR     DL,DL                   ;Use DL to carry number; init = 0
  1337.                XOR     BP,BP                   ;Use BP as number flag.
  1338. NEXT_PARAM:    LODSB                           ;Retrieve a byte.
  1339.                DEC     CX                      ;Decrement string length counter.
  1340.                JZ      PARSE_END               ;If zero, done.
  1341.                MOV     AH,QUOTE_TYPE           ;Else, retrieve quote type.
  1342.                OR      AH,AH                   ;If zero, not in string.
  1343.                JNZ     QUOTE_MODE              ;Else, go to string mode.
  1344.                CALL    CK_QUOTE                ;Is character a quote?
  1345.                JZ      NEXT_PARAM              ;If yes, ignore.
  1346.                CMP     AL,";"                  ;Else, is it semi-colon?
  1347.                JZ      STORE_NUMBER            ;If yes, number delimiter.
  1348.  
  1349.                SUB     AL,"0"                  ;Else, must be number; convert
  1350.                MOV     DH,AL                   ; to binary; save in DH.
  1351.                MOV     AX,10                   ;Multiply current total by ten.
  1352.                MUL     DL
  1353.                ADD     AL,DH                   ;Add new number.
  1354.                MOV     DL,AL                   ;Save in DL.
  1355.                MOV     BP,1                    ;Flag that number mode active.
  1356.                JMP     SHORT NEXT_PARAM        ;Next parameter.
  1357.  
  1358. STORE_NUMBER:  OR      BP,BP                   ;If number mode flag not set then
  1359.                JZ      NEXT_PARAM              ;semi-colon not prefaced with no.
  1360.                MOV     AL,DL                   ;Else, store number.
  1361.                STOSB
  1362.                JMP     SHORT NEXT_NUM          ;Reset number carrying registers.
  1363.  
  1364. QUOTE_MODE:    CMP     AL,AH                   ;Is current char a string ending
  1365.                JZ      NEXT_STRING             ; quote?  If yes, exit quote mode
  1366.                STOSB                           ;Else, store char as literal.
  1367.                JMP     SHORT NEXT_PARAM
  1368.  
  1369. ;----------------------------------------------------------------------------;
  1370. ; Remove duplicate assignments if removal leaves room for new assignment.    ;
  1371. ; If no duplicate and room, add new assignment, else flush buffer to screen. ;
  1372. ;----------------------------------------------------------------------------;
  1373.  
  1374. PARSE_END:     OR      BP,BP                   ;Was last parameter a number?
  1375.                JZ      CK_LENGTH               ;If no, skip.
  1376.                MOV     AL,DL                   ;Else, store the last number.
  1377.                STOSB
  1378. CK_LENGTH:     SUB     DI,OFFSET PARSE_BUFFER - 2   ;Calculate string length
  1379.                MOV     AX,DI                        ; including word for length.
  1380.                MOV     BX,WORD PTR PARSE_BUFFER     ;BL=new first ASCII; BH=2nd.
  1381.                MOV     CX,5                         ;String length has to be at
  1382.                OR      BL,BL                   ;least word + 2 for old + new = 5
  1383.                JZ      CK_LEGAL                ; for extended key reassignment.
  1384.                DEC     CX                      ;And word + 1 for old + new = 4
  1385. CK_LEGAL:      CMP     AX,CX                   ; for regular ASCII reassignment.
  1386.                JB      ASSIGN_FLUSH            ;If not, illegal; flush buffer.
  1387.                MOV     BP,BUFFER_END           ;BP to carry buffer end pointer.
  1388.                CALL    CK_MATCH                ;Is char already reassigned?
  1389.                JC      CK_ROOM                 ;If no, check room for new.
  1390.  
  1391. CK_REMOVE:     MOV     CX,DX                   ;REASSIGN_END - string end
  1392.                SUB     CX,SI                   ; = bytes to move.
  1393.                JZ      CK_ROOM                 ;If zero, last string.
  1394.                SUB     DX,[DI]                 ;Is REASSIGN_END - old string
  1395.                ADD     DX,AX                   ; + new string >
  1396.                CMP     DX,BP                   ; BUFFER_END?
  1397.                JA      ASSIGN_FLUSH            ;If yes, flush buffer to screen.
  1398.                REP     MOVSB                   ;Else, move them down in buffer.
  1399.                JMP     SHORT STORE_NEW
  1400.  
  1401. CK_ROOM:       ADD     DX,AX                   ;New string + current strings.
  1402.                CMP     DX,BP                   ;Greater than buffer size?
  1403.                JA      ASSIGN_FLUSH            ;If yes, flush new string.
  1404. STORE_NEW:     MOV     SI,OFFSET PARSE_BUFFER  ;Else, room for new string.
  1405.                STOSW                           ;Store string length first.
  1406.                MOV     CX,AX                   ;Adjust counter.
  1407.                DEC     CX
  1408.                DEC     CX
  1409.                REP     MOVSB                   ;Store the actual string.
  1410.                MOV     REASSIGN_END,DI         ;Store new string end.
  1411.                RET
  1412.  
  1413. ASSIGN_FLUSH:  MOV     AL,"p"                  ;If buffer full, flush string
  1414.                JMP     FLUSH_BUFFER            ; including ending "p" command.
  1415.  
  1416. ;------------------------------------------------------------------------------;
  1417. ; INPUT:  BL = first ASCII code to match; BH = extended if BL = 0              ;
  1418. ; OUTPUT: CY = 1 if no match found; CY = 0 if match found.                     ;
  1419. ;         DI points to string length of match; DI+2 points to start of string. ;
  1420. ;         SI = end of string; DX = REASSIGN_END; BP = BUFFER_END               ;
  1421. ;------------------------------------------------------------------------------;
  1422.  
  1423. CK_MATCH:      MOV     DX,REASSIGN_END                ;Current strings end.
  1424.                MOV     SI,OFFSET REASSIGNMENT_BUFFER  ;Point to buffer.
  1425. NEXT_MATCH:    MOV     DI,SI                          ;Current record.
  1426.                CMP     DI,DX                   ;End of strings?
  1427.                JAE     NO_MATCH                ;If yes, no match.
  1428.                MOV     CX,[DI+2]               ;CL=current first ASCII; CH=2nd
  1429.                ADD     SI,[DI]                 ;Point to next record.
  1430.                CMP     BL,CL                   ;First characters match?
  1431.                JNZ     NEXT_MATCH              ;If no, check next record.
  1432.                OR      BL,BL                   ;Extended code? ie zero.
  1433.                JNZ     MATCH                   ;If no, then match.
  1434.                CMP     BH,CH                   ;Else, check second code.
  1435.                JNZ     NEXT_MATCH              ;If not same, no match.
  1436. MATCH:         CLC                             ;Else return with CY = 0
  1437.                RET
  1438.  
  1439. NO_MATCH:      STC                             ;No match; CY = 1.
  1440.                RET
  1441.  
  1442. ;----------------------------------------------------------------------;
  1443. ; Buffer area will write over disposable data and initialization code. ;
  1444. ;----------------------------------------------------------------------;
  1445.  
  1446. ESC_BUFFER            =       $
  1447. NUMBER_BUFFER         =       ESC_BUFFER + ESC_BUFFER_SIZE
  1448. PARSE_BUFFER          =       NUMBER_BUFFER
  1449. DEVICE_STATUS_BUFFER  =       PARSE_BUFFER + ESC_BUFFER_SIZE
  1450. DEVICE_STATUS_SIZE    =       11
  1451. REASSIGNMENT_BUFFER   =       DEVICE_STATUS_BUFFER + DEVICE_STATUS_SIZE
  1452.  
  1453. ;              DISPOSABLE DATA
  1454. ;              ---------------
  1455.  
  1456. SYNTAX         LABEL   BYTE
  1457. DB      "Syntax:  ANSI [FAST | SLOW][ON | OFF][KON | KOFF][PON | POFF]",CR,LF ;:
  1458. DB      "              [/B nnn][/C][/Q][/U][/T][/S][/P n]",CR,LF ;. ;@       ;:
  1459. DB      "FAST     = direct screen writes; default",CR,LF                    ;:
  1460. DB      "SLOW     = screen writes via BIOS",CR,LF                           ;:
  1461. DB      "ON/OFF   = active/inactive; default is ON",CR,LF                   ;:
  1462. DB      "KON/KOFF = active/inactive reassignments; default is ON",CR,LF     ;:
  1463. DB      "PON/POFF = active/inactive NEW reassignments; default is ON",CR,LF ;:
  1464. DB      "nnn = buffer size in bytes (0 - 60K) reserved for key reassignment; "
  1465. DB      "default 200",CR,LF
  1466. DB      "/Q  = Quiet, no output when executed",CR,LF                        ;:
  1467. DB      "/U  = Uninstall",CR,LF                                             ;:
  1468. DB      "/T  = Test if loaded",CR,LF                                        ;$
  1469. if PCB                                            ;$
  1470. DB      "/S  = Load stats from ANSICOM.SYS",CR,LF                           ;@
  1471. endif                                             ;$
  1472. DB      "/Pn = Protect n lines from scrolling at top"                       ;.
  1473. CR_LF   DB     CR,LF,LF,"$"
  1474.  
  1475. STATUS_MSG     DB      "Status: $"
  1476. BUFFER_MSG     DB      CR,LF,"Buffer size: $"
  1477. BYTES_FREE     DB      CR,LF,"Bytes free:  $"
  1478. ANSI_SYS_MSG   DB      "ANSI.SYS is installed so "
  1479. NOT_INSTALLED  DB      "ANSI.COM not installed",CR,LF,"$"
  1480. CON            DB      "CON"
  1481. CON_OFFSET     EQU     10
  1482. QUIET          DB      0                             ;| Quiet Mode
  1483. SYNTAX_FLAG    DB      0                             ;; Syntax Display Flag
  1484.  
  1485. SIZE_MSG       DB      "Uninstall to change buffer size",CR,LF,LF,"$"
  1486. UNLOAD_MSG     DB      "ANSI can't be uninstalled",CR,LF
  1487.                DB      "Uninstall resident programs in reverse order",CR,LF,"$"
  1488. NOT_ENOUGH     DB      "Not enough memory",CR,LF,"$"
  1489. ALLOCATE_MSG   DB      "Memory allocation error",CR,LF,BELL,"$"
  1490. INSTALL_MSG    DB      "Installed",CR,LF,"$"
  1491. UNINSTALL_MSG  DB      "Uninstalled",CR,LF,"$"
  1492. if PCB                                            ;$
  1493. NO_FILE_MSG    DB      "ANSICOM.SYS not found",CR,LF,"$"                ;@
  1494. FILE_ERROR_MSG DB      "Error reading ANSICOM.SYS",CR,LF,"$"            ;@
  1495. FILE_NAME      DB      "ANSICOM.SYS",0                                  ;@
  1496. endif                                             ;$
  1497. ;--------------------------------------------------------------------;
  1498. ; Search memory for a copy of our code, to see if already installed. ;
  1499. ;--------------------------------------------------------------------;
  1500.  
  1501. INITIALIZE     PROC    NEAR
  1502.                CLD                             ;All string operations forward.
  1503.                MOV     BX,OFFSET START         ;Point to start of code.
  1504.                NOT     BYTE PTR [BX]           ;Change a byte so no false match.
  1505.                XOR     DX,DX                   ;Start at segment zero.
  1506.                MOV     AX,CS                   ;Store our segment in AX.
  1507. NEXT_PARAG:    INC     DX                      ;Next paragraph.
  1508.                MOV     ES,DX
  1509.                CMP     DX,AX                   ;Is it our segment?
  1510.                JZ      ANNOUNCE                ;If yes, search is done.
  1511.                MOV     SI,BX                   ;Else, point to our signature.
  1512.                MOV     DI,BX                   ; and offset of possible match.
  1513.                MOV     CX,16                   ;Check 16 bytes for match.
  1514.                REP     CMPSB
  1515.                JNZ     NEXT_PARAG              ;If no match, keep looking.
  1516.  
  1517. ;------------------------------------------------;
  1518.  
  1519. ANNOUNCE:                                      ;|
  1520.                MOV     SI,81H                  ;Point to command line.
  1521. NEXT_CAP:      LODSB                           ;Capitalize parameters.
  1522.                CMP     AL,CR
  1523.                JZ      PARSE
  1524.                CMP     AL,"a"
  1525.                JB      NEXT_CAP
  1526.                CMP     AL,"z"
  1527.                JA      NEXT_CAP
  1528.                AND     BYTE PTR [SI - 1],5FH
  1529.                JMP     SHORT NEXT_CAP
  1530.  
  1531. ;------------------------------------------------;
  1532.  
  1533. PARSE:         MOV     SI,81H                  ;Point to command line again.
  1534. NEXT_PARA:     XOR     AX,AX                   ;Position in status parameters.
  1535.                MOV     BX,4                    ;Status parameters each 4 bytes.
  1536. NEXT_STATUS:   MOV     DI,OFFSET PARAMETERS    ;Point to "OFF ON  SLOWFAST"
  1537.                ADD     DI,AX                   ;Point to next parameter.
  1538.                ADD     AX,BX
  1539.                CMP     AX,LAST_PARAMETER       ;:Check all 8 possible statuses
  1540.                JA      CK_SWITCHES
  1541.                PUSH    SI                      ;Save command line pointer.
  1542.                MOV     CX,2                    ;Check first two bytes for match.
  1543.                CMP     AX,20                   ;: 3 Bytes for
  1544.                JB      Len_OK                  ;:   KON | KOFF | PON | POFF
  1545.                INC     CX                      ;:
  1546. Len_OK:                                        ;:
  1547.                REP     CMPSB
  1548.                POP     SI                      ;Recover command line pointer.
  1549.                JNZ     NEXT_STATUS
  1550.  
  1551.                DIV     BL                      ;If match, divide offset by four.
  1552. ;:
  1553. ;:  Next 12 lines of routine changed
  1554. ;:
  1555. ;:             MOV     CL,1                    ;Set a bit to match offset.
  1556. ;:NEXT_SHIFT:  SHL     CL,1
  1557. ;:             DEC     AL
  1558. ;:             JNZ     NEXT_SHIFT
  1559. ;:             SHR     CL,1                    ;Adjust.
  1560. ;:             MOV     AH,STATUS_MASK          ;Retrieve appropriate ON/OFF
  1561. ;:             CMP     CL,ON                   ; or FAST/SLOW mask.
  1562. ;:             JBE     ADD_STATUS
  1563. ;:             ROL     AH,1
  1564. ;:             ROL     AH,1
  1565. ;:
  1566. ;:ADD_STATUS:  AND     ES:STATUS,AH            ;Mask off old status.
  1567. ;:             OR      ES:STATUS,CL            ;Add new status.
  1568. ;:
  1569.                MOV     CL,AL                   ;:place count in CL (1 - 8)
  1570.                MOV     AX,STATUS_MASK          ;:Retrieve appropriate ON/OFF
  1571.                                                ;:FAST|SLOW|KON|KOFF|PON|POFF
  1572.                DEC     CL                      ;:Make 1 - 8 into 0 - 7
  1573.                JZ      Skip_1                  ;:In position already if zero
  1574.                SHL     AL,CL                   ;:Shift bit into position
  1575. Skip_1:        SHR     CL,1                    ;:divide count by 2
  1576.                JZ      Skip_2                  ;:
  1577.                ROL     AH,CL                   ;:Shift Mask into position
  1578.                ROL     AH,CL                   ;:
  1579. Skip_2:                                        ;:
  1580.  
  1581.                AND     ES:STATUS,AH            ;Mask off old status.
  1582.                OR      ES:STATUS,AL            ;:Add new status.
  1583.                INC     SI                      ;Bump command line pointer.
  1584.                INC     SI
  1585.  
  1586. CK_SWITCHES:   LODSB                           ;Get a byte.
  1587.                CMP     AL,CR                   ;Is it carriage return?
  1588.                JNE     QUES                    ;$
  1589.                JMP     INSTALL                 ;If yes, done here.
  1590. QUES:          CMP     AL,"?"                  ;;Request for Syntax?
  1591.                JNE     CK_SW                   ;; No -
  1592.                MOV     BYTE PTR SYNTAX_FLAG, 1 ;; Yes-Show Syntax
  1593. CK_SW:         CMP     AL,"/"                  ;;Is there a switch character?
  1594.                JNE     NEXT_PARA               ;;If no, keep looking.
  1595. GOT_SWITCH:    LODSB                           ;;Else, get the switch character.
  1596.                CMP     AL,"B"                  ;Is it "B" ?
  1597.                JNZ     CK_C                    ;If no, check "C".
  1598.                CALL    CK_INSTALLED            ;Else, see if already installed.
  1599.                JZ      GET_SIZE                ;If no, get buffer request size.
  1600.                MOV     DX,OFFSET SIZE_MSG      ;Else, display error message.
  1601.                CALL    PRINT_STRING
  1602. NEXT_PARA2:    JMP     SHORT NEXT_PARA
  1603. GET_SIZE:      CALL    DECIMAL_INPUT           ;Get number parameter.
  1604.                CMP     BX,REASSIGNMENT_MAX     ;If greater than maximum, use
  1605.                JBE     STORE_BUFFER            ; maximum, else use requested
  1606.                MOV     BX,REASSIGNMENT_MAX     ; size.
  1607. STORE_BUFFER:  MOV     REASSIGNMENT_SIZE,BX
  1608.                ADD     BX,OFFSET REASSIGNMENT_BUFFER  ;Calculate end of buffer.
  1609.                MOV     BUFFER_END,BX
  1610.                JMP     NEXT_PARA               ;;Too far for direct jump
  1611.  
  1612. CK_C:          CMP     AL,"C"                  ;Is it "C" ?
  1613. if PCB                                         ;$
  1614.                JNZ     CK_S                    ;@ If not, check "S".
  1615. else                                           ;$
  1616.                JNZ     CK_P                    ;$ If not, check "P".
  1617. endif                                          ;$
  1618.                MOV     ES:REASSIGN_END,OFFSET REASSIGNMENT_BUFFER  ;Clear buffer
  1619.                JMP     NEXT_PARA               ;Else, next parmater.
  1620. if PCB                                         ;$
  1621. CK_S:          CMP     AL,"S"                  ;@ Is It "S" ?
  1622.                JNZ     CK_P                    ;. If not, check "P".
  1623.                CALL    LOAD_STATS              ;@ Yes, Load Stats
  1624.                JMP     NEXT_PARA2              ;@ Next parameter (indirect)
  1625. endif                                          ;$
  1626. CK_P:          CMP     AL,"P"                  ;. Is it "P" ?
  1627.                JNZ     CK_Q                    ;|If not, check "Q".
  1628.                CMP     BYTE PTR [SI], '*'      ;$Use current row-1?
  1629.                JNE     CK_PN                   ;$no
  1630.                PUSH    SI                      ;$Get
  1631.                CALL    GET_BIOS_DATA           ;$   current
  1632.                MOV     BL, ES:CURSOR_ROW       ;$          row
  1633.                DEC     BL                      ;$             -1
  1634.                POP     SI                      ;$
  1635.                JMP     CK_PS                   ;$
  1636. CK_PN:         CALL    DECIMAL_INPUT           ;. Get number of lines
  1637. CK_PS:         MOV     ES:START_SCROLL,BL      ;. Store the value
  1638.                JMP     NEXT_PARA2              ;. Next parameter (indirect)
  1639. CK_Q:          CMP     AL,"Q"                  ;|See if Quiet Mode
  1640.                JNE     CK_U                    ;|If not, check "U".
  1641.                NOT     QUIET                   ;|If yes turn on Quiet
  1642.                JMP     NEXT_PARA               ;Else, next parmater.
  1643. CK_U:          CMP     AL,"U"                  ;Is it "U" ?
  1644.                JE      DO_U                    ;If yes, try to uninstall.
  1645.                CMP     AL,"T"                  ;; Test if Installed
  1646.                JE      DO_U
  1647.                MOV     BYTE PTR SYNTAX_FLAG, 1 ;; Syntax Error
  1648.                JMP     NEXT_PARA               ;Else, next parmater.
  1649.  
  1650. ;------------------------------------------------;
  1651.  
  1652. INSTALL:
  1653.                MOV     DX,OFFSET SIGNATURE     ;|Display our signature.
  1654.                CALL    PRINT_STRING            ;|
  1655.                CMP     BYTE PTR SYNTAX_FLAG,0  ;;Display Syntax?
  1656.                JE      SKIP_SYNTAX             ;;No
  1657.                MOV     DX,OFFSET SYNTAX        ;|Yes, Display syntax.
  1658.                CALL    PRINT_STRING            ;|
  1659. SKIP_SYNTAX:   CALL    STATUS_REPORT          ;;|Display status.
  1660.                CALL    CK_INSTALLED            ;Check if already installed.
  1661.                JZ      CK_AVAILABLE            ;If no, see if enough memory.
  1662.                XOR     AL,AL                   ;;Else, done.
  1663. EXIT2:         JMP     EXIT                    ;Exit with ERRORLEVEL = 0.
  1664.  
  1665. DO_U:          CALL    CK_INSTALLED            ;Else, see if installed.
  1666.                MOV     DX,OFFSET NOT_INSTALLED ;If no, exit with error message.
  1667.                JZ      LILLY_PAD               ;Too far for short jump.
  1668.                CMP     AL,"T"                  ;;Was it a test
  1669.                MOV     AL, STATUS              ;$return switches as
  1670.                JE      EXIT2                   ;;$Yes Too far for short jump.
  1671.                JMP     UNINSTALL               ;$Else, uninstall.
  1672.  
  1673. ;--------------------------------;
  1674. ; This is the install procedure. ;
  1675. ;--------------------------------;
  1676.  
  1677. CK_AVAILABLE:  MOV     BP,OFFSET REASSIGNMENT_BUFFER   ;TSR ends at end
  1678.                ADD     BP,REASSIGNMENT_SIZE            ; of reassignment buffer.
  1679.                ADD     BP,15                           ;Round up.
  1680.                CMP     BP,DS:[6]               ;Buffer > PSP bytes in segment?
  1681.                MOV     DX,OFFSET NOT_ENOUGH    ;If yes, exit without installing
  1682.                JBE     CK_ANSI                 ;@
  1683.                JMP     MSG_EXIT                ;@with message
  1684. CK_ANSI:       MOV     AX,3529H                ;@Get undocumented INT 29 vector.
  1685.                INT     21H
  1686.                MOV     SI,OFFSET CON           ;Does it point to ANSI.SYS?
  1687.                MOV     DI,CON_OFFSET           ;Check by looking for "CON"
  1688.                MOV     CX,3                    ; as device name.
  1689.                REP     CMPSB
  1690.                MOV     DX,OFFSET ANSI_SYS_MSG  ;Exit with error message if
  1691. LILLY_PAD:     JZ      MSG_EXIT                ;ANSI.SYS loaded.
  1692.  
  1693.                MOV     OLD_INT_29[0],BX        ;Else save old interrupt.
  1694.                MOV     OLD_INT_29[2],ES
  1695.                MOV     DX,OFFSET ANSI_INT_29   ;Install new interrupt.
  1696.                MOV     AX,2529H
  1697.                INT     21H
  1698.                MOV     AX,3516H                ;Get INT 16 vector.
  1699.                INT     21H
  1700.                MOV     OLD_INT_16[0],BX        ;Save old interrupt.
  1701.                MOV     OLD_INT_16[2],ES
  1702.                MOV     DX,OFFSET ANSI_INT_16   ;Install new interrupt.
  1703.                MOV     AX,2516H
  1704.                INT     21H
  1705.                MOV     AX,3521H                ;Get DOS 21h interrupt.
  1706.                INT     21H
  1707.                MOV     OLD_INT_21[0],BX        ;Save old interrupt.
  1708.                MOV     OLD_INT_21[2],ES
  1709.                MOV     DX,OFFSET ANSI_INT_21   ;Install new interrupt.
  1710.                MOV     AX,2521H
  1711.                INT     21H
  1712. if PCB                                            ;$
  1713.                MOV     AX,3508H                ;@ Get INT 08 vector.
  1714.                INT     21H                     ;@
  1715.                MOV     OLD_INT_08[0],BX        ;@ Save old interrupt.
  1716.                MOV     OLD_INT_08[2],ES        ;@
  1717.                MOV     DX,OFFSET ANSI_INT_08   ;@ Install new interrupt.
  1718.                MOV     AX,2508H                ;@
  1719.                INT     21H                     ;@
  1720. endif                                             ;$
  1721.                MOV     AX,DS:[2CH]             ;Get environment segment.
  1722.                MOV     ES,AX
  1723.                MOV     AH,49H                  ;Free up environment.
  1724.                INT     21H
  1725.  
  1726.                MOV     DX,OFFSET INSTALL_MSG   ;Display install message.
  1727.                CALL    PRINT_STRING
  1728.                CALL    FLUSH_END               ;Setup the number buffer.
  1729.                MOV     DX,BP                   ;Retrieve resident byte request.
  1730.                MOV     CL,4
  1731.                SHR     DX,CL                   ;Convert to paragraphs.
  1732.                MOV     AX,3100H                ;Return error code of zero.
  1733.                INT     21H                     ;Terminate but stay resident.
  1734.  
  1735. ;-------------------------------------------------------------------;
  1736. ; Exit.  Return ERRORLEVEL code 0 if successful, 1 if unsuccessful. ;
  1737. ;-------------------------------------------------------------------;
  1738.  
  1739. MSG_EXIT:      CALL    PRINT_STRING
  1740. ERROR_EXIT:    MOV     AL,1                    ;ERRORLEVEL = 1.
  1741. EXIT:          MOV     AH,4CH                  ;Terminate.
  1742.                INT     21H
  1743.  
  1744. ;---------------------------------------------------;
  1745. ; This subroutine uninstalls the resident ANSI.COM. ;
  1746. ;---------------------------------------------------;
  1747.  
  1748. UNINSTALL:     AND     ES:STATUS,NOT ON        ;Turn OFF ANSI, just in case
  1749.                OR      ES:STATUS,OFF           ; can't uninstall.
  1750.                MOV     CX,ES                   ;Save segment in CX.
  1751.                MOV     AX,3529H                ;Get interrupt 29h.
  1752.                INT     21H
  1753.                CMP     BX,OFFSET ANSI_INT_29   ;Has it been hooked by another?
  1754. ife PCB                                        ;$
  1755.                JNZ     UNINSTALL_ERR           ;$If no, exit with error message.
  1756. else                                           ;$
  1757.                JNZ     UNINSTALL_ERR2          ;@If no, exit with error message.
  1758. endif                                          ;$
  1759.                MOV     BX,ES
  1760.                CMP     BX,CX                   ;Is the segment vector same?
  1761. ife PCB                                        ;$
  1762.                JNZ     UNINSTALL_ERR           ;$If no, exit with error message.
  1763. else                                           ;$
  1764.                JNZ     UNINSTALL_ERR2          ;@If no, exit with error message.
  1765.                MOV     AX,3508H                ;@Get interrupt 08h.
  1766.                INT     21H                     ;@
  1767.                CMP     BX,OFFSET ANSI_INT_08   ;@Has it been hooked by another?
  1768.                JNZ     UNINSTALL_ERR           ;@If yes, exit with error message.
  1769.                MOV     BX,ES                   ;@
  1770.                CMP     BX,CX                   ;@Is the segment vector same?
  1771. UNINSTALL_ERR2:JNZ     UNINSTALL_ERR           ;@If no, exit with error message.
  1772. endif                                          ;$
  1773.                MOV     AX,3516H                ;Get interrupt 16h.
  1774.                INT     21H
  1775.                CMP     BX,OFFSET ANSI_INT_16   ;Has it been hooked by another?
  1776.                JNZ     UNINSTALL_ERR           ;If yes, exit with error message.
  1777.                MOV     BX,ES
  1778.                CMP     BX,CX                   ;Is the segment vector same?
  1779.                JNZ     UNINSTALL_ERR           ;If no, exit with error message.
  1780.  
  1781.                MOV     AX,3521H                ;Get interrupt 21h.
  1782.                INT     21H
  1783.                CMP     BX,OFFSET ANSI_INT_21   ;Has it been hooked by another?
  1784.                JNZ     UNINSTALL_ERR           ;If yes, exit with error message.
  1785.                MOV     BX,ES
  1786.                CMP     BX,CX                   ;Is the segment vector same?
  1787.                JNZ     UNINSTALL_ERR           ;If no, exit with error message.
  1788.  
  1789.                MOV     AH,49H                  ;Return memory to system pool.
  1790.                INT     21H
  1791.                MOV     DX,OFFSET ALLOCATE_MSG
  1792.                JC      MSG_EXIT                ;Display message if problem.
  1793.  
  1794.                MOV     DX,ES:OLD_INT_29[0]     ;Restore old INT 29.
  1795.                MOV     DS,ES:OLD_INT_29[2]
  1796.                MOV     AX,2529H
  1797.                INT     21H
  1798. if PCB                                         ;$
  1799.                MOV     DX,ES:OLD_INT_08[0]     ;@Restore old INT 08.
  1800.                MOV     DS,ES:OLD_INT_08[2]     ;@
  1801.                MOV     AX,2508H                ;@
  1802.                INT     21H                     ;@
  1803. endif                                          ;$
  1804.                MOV     DX,ES:OLD_INT_16[0]     ;Restore old INT 16.
  1805.                MOV     DS,ES:OLD_INT_16[2]
  1806.                MOV     AX,2516H
  1807.                INT     21H
  1808.                MOV     DX,ES:OLD_INT_21[0]     ;Restore old INT 21.
  1809.                MOV     DS,ES:OLD_INT_21[2]
  1810.                MOV     AX,2521H
  1811.                INT     21H
  1812.  
  1813.                PUSH    CS
  1814.                POP     DS                      ;Point to our data.
  1815.                MOV     DX,OFFSET UNINSTALL_MSG ;Display uninstall message.
  1816.                CALL    PRINT_STRING
  1817.                OR      AL,AL                   ;Exit with ERRORLEVEL = 0.
  1818.                JMP     EXIT
  1819.  
  1820. UNINSTALL_ERR: MOV     ES,CX                   ;If error, display OFF status.
  1821.                CALL    STATUS_REPORT
  1822.                MOV     DX,OFFSET UNLOAD_MSG    ;And exit with error message.
  1823.                JMP     MSG_EXIT
  1824. INITIALIZE     ENDP
  1825.  
  1826. ;--------------------------------------------------;
  1827. ; INPUT:  SI points to parameter start.            ;
  1828. ; OUTPUT: SI points to parameter end; BX = number. ;
  1829. ;--------------------------------------------------;
  1830.  
  1831. DECIMAL_INPUT  PROC    NEAR
  1832.                XOR     BX,BX                   ;Start with zero as number.
  1833. NEXT_DECIMAL:  LODSB                           ;Get a character.
  1834.                CMP     AL,CR                   ;Carriage return?
  1835.                JZ      ADJUST_DEC              ;If yes, done here.
  1836.                CMP     AL,"/"                  ;Forward slash?
  1837.                JZ      ADJUST_DEC              ;If yes, done here.
  1838.                SUB     AL,"0"                  ;ASCII to binary.
  1839.                JC      NEXT_DECIMAL            ;If not between 0 and 9, skip.
  1840.                CMP     AL,9
  1841.                JA      NEXT_DECIMAL
  1842.                CBW                             ;Convert byte to word.
  1843.                XCHG    AX,BX                   ;Swap old and new number.
  1844.                MOV     CX,10                   ;Shift to left by multiplying
  1845.                MUL     CX                      ; last entry by ten.
  1846.                JC      DECIMAL_ERROR           ;If carry, too big.
  1847.                ADD     BX,AX                   ;Add new number and store in BX.
  1848.                JNC     NEXT_DECIMAL            ;If not carry, next number.
  1849. DECIMAL_ERROR: MOV     BX,-1                   ;Else, too big; return -1.
  1850.  
  1851. ADJUST_DEC:    DEC     SI                      ;Adjust pointer.
  1852.                RET
  1853. DECIMAL_INPUT  ENDP
  1854.  
  1855. ;-------------------------------------------------------;
  1856. ; OUTPUT: ZR = 1 if not installed; ZR = 0 if installed. ;
  1857. ;-------------------------------------------------------;
  1858.  
  1859. CK_INSTALLED:  PUSH    AX                      ;;
  1860.                MOV     AX,ES
  1861.                MOV     BX,CS
  1862.                CMP     AX,BX                   ;Compare segments.
  1863.                POP     AX                      ;;
  1864.                RET
  1865.  
  1866. ;------------------------------------------------;
  1867.  
  1868. STATUS_REPORT: MOV     DX,OFFSET STATUS_MSG
  1869.                CALL    PRINT_STRING            ;Display "Status: ".
  1870.                MOV     BL,ES:STATUS
  1871.                MOV     BH,1
  1872. NEXT_REPORT:   TEST    BL,BH
  1873.                JZ      LOOP_STATUS
  1874.  
  1875.                MOV     DL,BH
  1876. ;:
  1877. ;: Next 9 Lines changed
  1878. ;:
  1879. ;:             MOV     AX,-1
  1880. ;:NEXT_BIT:    INC     AX
  1881. ;:             SHR     DL,1
  1882. ;:             JNC     NEXT_BIT
  1883. ;:             SHL     AX,1
  1884. ;:             SHL     AX,1
  1885. ;:             MOV     SI,OFFSET PARAMETERS    ;Display appropriate ON or OFF,
  1886. ;:             ADD     SI,AX                   ; SLOW or FAST.
  1887. ;:             MOV     CX,4
  1888. ;:
  1889.                MOV     SI,OFFSET PARAMETERS    ;:Display appropriate ON or OFF,
  1890.                                                ;: SLOW|FAST.  KON|KOFF|PON|POFF
  1891.                MOV     CX,4                    ;:Each four characters long
  1892. NEXT_BIT:      SHR     DL,1                    ;:Is this our Word?
  1893.                JC      REPORT                  ;:Yes - Print it
  1894.                ADD     SI,CX                   ;:No  - Skip over it
  1895.                JMP     NEXT_BIT                ;:test the next bit
  1896. REPORT:        LODSB
  1897.                CALL    PRINT_CHAR
  1898.                LOOP    REPORT
  1899.                MOV     AL, " "                 ;: Space words
  1900.                CALL    PRINT_CHAR              ;:
  1901.  
  1902. LOOP_STATUS:   SHL     BH,1
  1903.                JNC     NEXT_REPORT             ;: Check all 8 bits
  1904.                                                ;:
  1905.                MOV     DX,OFFSET BUFFER_MSG    ;Display "Buffer size: ".
  1906.                CALL    PRINT_STRING
  1907.                MOV     AX,ES:REASSIGNMENT_SIZE
  1908.                PUSH    AX
  1909.                XOR     BP,BP
  1910.                CALL    DECIMAL_OUT             ;Display the size.
  1911.                MOV     DX,OFFSET BYTES_FREE    ;Display "Bytes free: ".
  1912.                CALL    PRINT_STRING
  1913.                POP     AX
  1914.                ADD     AX,OFFSET REASSIGNMENT_BUFFER
  1915.                SUB     AX,ES:REASSIGN_END
  1916.                CALL    DECIMAL_OUT             ;Display the bytes free.
  1917.                MOV     DX,OFFSET CR_LF
  1918.                CALL    PRINT_STRING
  1919.                RET
  1920.  
  1921. ;------------------------------------------------;
  1922.  
  1923. PRINT_CHAR:    MOV     DL,AL
  1924.                MOV     AH,2                    ;Print character via DOS.
  1925.                OR      AL,AL                   ;:Skip NULLs
  1926.                JNZ     SHORT DOS_INT           ;:
  1927.                RET                             ;:
  1928.  
  1929. PRINT_STRING:  MOV     AH,9                    ;Print string via DOS.
  1930. DOS_INT:       CMP     QUIET,0                 ;|Do we suppress output
  1931.                JNE     NO_PRINT                ;|Yes
  1932.                INT     21H                     ;|No
  1933. NO_PRINT:                                      ;|
  1934.                RET
  1935. if PCB                                         ;$
  1936. LOAD_STATS:    MOV    DX,OFFSET FILE_NAME      ;@ Stat filename
  1937.                MOV    AX,3D00H                 ;@ Open File
  1938.                INT    21H                      ;@ DOS Interupt
  1939.                MOV    DX,OFFSET NO_FILE_MSG    ;@ Assume no file
  1940.                JNC    OPEN_OK                  ;@ Ok, So far
  1941. MSG_EXIT2:     JMP    MSG_EXIT                 ;@ No file found probably
  1942. OPEN_OK:       MOV    BX,AX                    ;@ This is our Handle number
  1943.                PUSH   DS                       ;@ Save DS
  1944.                PUSH   ES                       ;@ Set ES to DS
  1945.                POP    DS                       ;@
  1946.                MOV    DX, OFFSET SUB_LIST      ;@ Point to the Sub_List
  1947.                MOV    CX, SUB_LENGTH           ;@ Get the Length ot the List
  1948.                MOV    AH,3FH                   ;@ Read from Handle
  1949.                INT    21H                      ;@ DOS Interupt
  1950.                POP    DS                       ;@ Restore DS
  1951.                PUSHF                           ;@ Save results
  1952.                PUSH   AX                       ;@
  1953.                MOV    AH,3EH                   ;@ Close Handle
  1954.                INT    21H                      ;@ DOS Interupt
  1955.                POP    AX                       ;@ Restore results
  1956.                POPF                            ;@
  1957.                MOV    DX,OFFSET FILE_ERROR_MSG ;@ Assume an error occured
  1958.                JC     MSG_EXIT2                ;@ Yep, it did
  1959.                XCHG   AX,CX                    ;@ Swap Bytes Read
  1960.                JCXZ   MSG_EXIT2                ;@ Something went wrong
  1961.                CMP    AX,CX                    ;@ Did we read the full amount
  1962.                JNE    MSG_EXIT2                ;@ No
  1963.                RET                             ;@ All went well!
  1964. endif                                          ;$
  1965. _TEXT          ENDS
  1966.                END     START
  1967.